【发布时间】:2010-07-06 04:24:54
【问题描述】:
有些东西我只是没有得到,我正在寻求帮助以了解这里发生的事情。
我有一个自定义列表适配器(它只是扩展了 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>
在对保存列表的活动进行一些调整后,我运行了代码。我看到了我的页脚(以及作为所有内容的父级的选项卡小部件),但列表所在的区域是空的。
@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 并首先针对定义为资源的 xml 数组显示,应该可以正常显示。
-
我不太确定你在这里建议什么 - 如果我有一个 xml 数组,那么它并没有真正帮助我,因为我想使用我提供的使用光标的自定义数组适配器它。有趣的是,我将我一直在尝试制作的 XML 放入记事本示例中(它使用 SimpleCursorAdapter 和几个 XML 数组),我的页脚看起来没有问题。因此,基于此,您对您的适配器如何导致问题有任何提示吗?
标签: android listview sticky-footer