大佬教程收集整理的这篇文章主要介绍了android – 在ListActivity上使用setEmptyView的问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getListView().setEmptyView(findViewById(R.id.empty)); getListView().setTextFilterEnabled(true); setlistadapter(null);// to have empty list }
布局文件是:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/myScrollLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <FrameLayout android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1"> <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawSelectorOnTop="false" /> <!-- Here is the view to show if the list is emtpy --> <ScrollView android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/emptyText" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/contact_empty_help" android:textSize="20sp" android:textColor="?android:attr/textColorSecondary" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="10dip" android:lineSpacingMultiplier="0.92" /> </ScrollView> </FrameLayout> </LinearLayout>
字符串定义为:
<string name="contact_empty_help">"You don't have any contacts to display.\n\nTo add contacts,you have to:\n \n<li><font fgcolor="#ffffffff">Go to <b>Contacts</b></font> application to create new contacts\n</li> \n<li><font fgcolor="#ffffffff"><b>Import from VCF file</b></font>,this is available in Contacts menu,the file most be on the root of the SD card\n</li>" </string>
由于列表为空,它应该显示已定义的文本.我按照List8中的示例进行操作
https://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List8.html
https://developer.android.com/resources/samples/ApiDemos/res/layout/list_8.xml
以上是大佬教程为你收集整理的android – 在ListActivity上使用setEmptyView的问题全部内容,希望文章能够帮你解决android – 在ListActivity上使用setEmptyView的问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。