我addHeaderView
用来将视图项添加到顶部ListView
.我还要TextView
显示一条消息,说明列表中没有项目.
这是布局:
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/list_empty"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
Run Code Online (Sandbox Code Playgroud)
和Java代码:
final ListView listView = getListView();
final View view = getLayoutInflater().inflate(R.layout.list_item_add,
listView, false);
listView.addHeaderView(view, null, true);
Run Code Online (Sandbox Code Playgroud)
当ListView中有项目时,会显示标题,但如果删除列表中的所有项目(标题视图除外),则标题视图将消失.
我希望列表视图在列表视图中可见,是否列表中有项目.
谢谢,
sup*_*ell 36
@android:id/empty
从布局中删除视图,或覆盖/子类化适配器以返回falseisEmpty()
归档时间: |
|
查看次数: |
10603 次 |
最近记录: |