我只是没有得到一些东西,我正在寻求帮助以了解这里发生的事情。
我有一个自定义列表适配器(只是扩展了 BaseAdapter),我已经成功地使用它来生成和显示列表。现在我想在我的列表底部添加一个静态页脚。在查看了许多资源(特别是 this one))之后,我开始意识到我对使用 XML 的不情愿已经结束,并在名为 devices_list.xml 的文件中设置以下 xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:id="@+id/bottom_control_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ToggleButton android:id="@+id/bottom_control_toggle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textOff="Filter Favourites OFF"
android:textOn="Filter Favourites ON"/>
</LinearLayout>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_above="@id/bottom_control_bar">
</ListView>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_empty_list"
android:layout_above="@id/bottom_control_bar"/>
</RelativeLayout>
在对保存列表的 Activity 进行一些调整后,我运行了代码。我看到了我的页脚(以及所有内容的父标签小部件),但是列表所在的区域是空的。
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.devices_list);
db = new DbManager(this);
db.open();
AllCur = db.fetchAllDevices();
startManagingCursor(AllCur);
list = new DeviceListAdapter(this, AllCur); //make my custom list adapter
setListAdapter(list);
}
有什么方法可以将在我的 xml 中声明的 ListView 小部件与我的 DeviceListAdapter 链接起来吗?现在我很清楚,我并不完全确定这一切是如何运作的。任何澄清方面的帮助将不胜感激。
最佳答案
您将 ListView
和 TextView
都设置为 android:layout_above="@id/bottom_control_bar"
,这意味着 TextView
将与 ListView
重叠。而且,您已经说过您的 ListView
高度是 0dip
,这将使列表非常短。
我会将 ListView
定义为位于 TextView
上方并锚定到屏幕顶部 (android:layout_alignParentTop="true"
).
Is there some way to link up the ListView widget declared in my xml with my DeviceListAdapter?
您已经通过调用 setListAdapter()
实现了。
关于android - 自定义Listview Adapter,添加静态页脚,理解R.id.list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3181744/