50个Android开发技巧(24 处理ListView数据为空的情况)
原文地址:(http://blog.csdn.net/vector_yi/article/details/24936163)
<FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width= "fill_parent" android:layout_height= "fill_parent" android:orientation= "vertical" > <ListView android:id ="@+id/my_list_view" android:layout_width ="fill_parent" android:layout_height ="fill_parent" /> <ImageView android:id ="@+id/empty_view" android:layout_width ="fill_parent" android:layout_height ="fill_parent" android:src ="@drawable/empty_view" /> </FrameLayout>
再来看自定义的drawable/empty_view文件:
<shape xmlns:android = "http://schemas.android.com/apk/res/android" android:shape= "rectangle" > <solid android:color= "#AA00FF00" /> </shape>
public class MainActivity extends Activity { private ListView mListView; @Override public void onCreate (Bundle savedInstanceState ) { super. onCreate( savedInstanceState ); setContentView (R .layout .main ); mListView = (ListView ) findViewById (R .id .my_list_view ); mListView. setEmptyView (findViewById (R .id .empty_view )); /*String[] strs=new String[]{"1","2"}; ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,strs); mListView.setAdapter(adapter);*/ } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。