AdapterView在无数据情况下的界面显示
2016-11-05 18:31
190 查看
在布局文件中将空界面布局与listview布局放在同一个framelayout下,通过adapterview的setEmptyView方法设置空数据时显示的布局
布局文件activity_foodlist.xml部分代码如下
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_foodlistempty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="无菜单" />
<ListView
android:id="@+id/lv_foodList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</FrameLayout>
...
Activity中的部分实现代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_foodlist);
mFoods = initData();
Button btnStart = (Button)findViewById(R.id.btn_start);
ListView lvFoods = (ListView)findViewById(R.id.lv_foodList);
TextView tvEmpty = (TextView)findViewById(R.id.tv_foodlistempty);
EditText etMainFoodCount = (EditText)findViewById(R.id.et_mainFoodCount);
etFoodCount = (EditText)findViewById(R.id.et_foodCount);
lvFoods.setEmptyView(tvEmpty);
getData(mFoods, mFoods.size());
mViewAdapter = new ArrayAdapter<String>(this,
R.layout.testmenu_list_item, //listview需要一个布局文件来完成对item的布局
R.id.tv_testmenu_item, //确认在item布局中用于显示内容的控件id
mFoodList);
lvFoods.setAdapter(mViewAdapter);
...
}
当lv_foodList无数据时,显示tv_foodlistempty
布局文件activity_foodlist.xml部分代码如下
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_foodlistempty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="无菜单" />
<ListView
android:id="@+id/lv_foodList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</FrameLayout>
...
Activity中的部分实现代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_foodlist);
mFoods = initData();
Button btnStart = (Button)findViewById(R.id.btn_start);
ListView lvFoods = (ListView)findViewById(R.id.lv_foodList);
TextView tvEmpty = (TextView)findViewById(R.id.tv_foodlistempty);
EditText etMainFoodCount = (EditText)findViewById(R.id.et_mainFoodCount);
etFoodCount = (EditText)findViewById(R.id.et_foodCount);
lvFoods.setEmptyView(tvEmpty);
getData(mFoods, mFoods.size());
mViewAdapter = new ArrayAdapter<String>(this,
R.layout.testmenu_list_item, //listview需要一个布局文件来完成对item的布局
R.id.tv_testmenu_item, //确认在item布局中用于显示内容的控件id
mFoodList);
lvFoods.setAdapter(mViewAdapter);
...
}
当lv_foodList无数据时,显示tv_foodlistempty
相关文章推荐
- windows mobile中使用datagrid绑定并显示数据及得到界面显示的数据值
- Netstat用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况
- winform-我们约会吧! v1.0 by ShinePans 窗体程序,界面友好,约会功能看情况而,需收集数据---ShinePans
- 《项目经验》--后台一般处理程序向前台JS文件传递JSON,JS解析JSON,将数据显示在界面--显示在DropDownList 或 显示在动态创建的table中
- android好看表单界面设计(TableLayout)及查询数据列表显示1
- Netstat用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况
- 数据结构--如何对一个线性表里面的元素赋值,并且显示插入一个数据后的情况
- 数据库出现问号,界面能正常显示,如果数据的数据需要备份或者导出的操作
- MFC(5)读取AVI视频数据并且显示到界面窗口上源码
- myOpenChord 界面数据后台线程获取,动态显示实现
- 批量读取文件夹下的DR8光谱数据,并完成显示保存图片以及统计Z和Obj的分布情况
- 第二部分基本组件---2.1SQLite部分应用-自定义database中取出数据,listView做界面显示示例
- AjaxLoading:利用Ajax加载数据,并显示友好的等待界面
- 巧用CursorLoader实时更新界面上显示的数据
- SQL语句增加虚拟字段,并根据情况显示不同的数据。。。(已阅。。。未阅。。)
- 表A中的记录随时变化,程序显示A数据的界面中如何自动也跟着刷新?
- 从AVI中读取每帧数据显示到界面
- 孙其功陪你学之--QT界面程序经过网路与普通的linux应用程序进行数据传送的情况(UDP协议,非TCP协议):
- QT界面程序经过网路与普通的linux应用程序进行数据传送的情况
- [原创]在ASP.NET环境下完整的datagrid填充数据后界面动态显示填充方案