Android 處理空列表的方法(必看篇)
更新時間:2017年04月18日 10:13:33 投稿:jingxian
下面小編就為大家?guī)硪黄狝ndroid 處理空列表的方法(必看篇)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
android中ListView 用來展示數(shù)據(jù),如果列表為空的狀態(tài),可以通過setEmpty(View)方法設置為空時顯示的內容。

布局xml
<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>
代碼:
public class Hack24Activity extends Activity {
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hack24);
mListView = (ListView) findViewById(R.id.my_list_view);
mListView.setEmptyView(findViewById(R.id.empty_view));
}
}
以上這篇Android 處理空列表的方法(必看篇)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
自定義RadioButton和ViewPager實現(xiàn)TabHost帶滑動的頁卡效果
在工作中又很多需求都不是android系統(tǒng)自帶的控件可以達到效果的所以這個時候就要自定義控件來達到效果:使用自定義RadioButton和ViewPager實現(xiàn)TabHost帶滑動的頁卡效果2013-01-01
Android中ExpandableListView使用示例詳解
這篇文章主要為大家詳細介紹了Android中ExpandableListView使用示例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10
Android利用Chronometer實現(xiàn)倒計時功能
這篇文章主要為大家詳細介紹了Android利用Chronometer實現(xiàn)倒計時功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11

