【发布时间】:2011-06-08 07:35:02
【问题描述】:
在ListActivity中可以使用this.getListView().addFooterView(footerView);
但是如果我使用 Activity 它就不能使用this.getListView()
我该怎么办?
【问题讨论】:
标签: android android-activity listactivity
在ListActivity中可以使用this.getListView().addFooterView(footerView);
但是如果我使用 Activity 它就不能使用this.getListView()
我该怎么办?
【问题讨论】:
标签: android android-activity listactivity
每当您使用Activity 时,您都将your_layout.xml 设置为您的Activity 的ContentView。所以ListView 应该在your_layout.xml 中。
ListView 应该在 xml 文件中定义一个 id 属性,例如:(android:id="@+id/list")。
您可以通过以下方式获得 ListView 对象:
setContentView(R.layout.your_layout);
ListView list = (ListView)findViewById(R.id.list);
list.addFooterView(view);
当你使用ListActivity 时,你会通过调用方法得到你的ListView
ListView list = getListView(); // OR you can do
ListView list = (ListView)findViewById(android.R.id.list); //consider the android prefix..
请注意,在为ListActivity 定义任何layout.xml 时,您的布局中将有一个ListView,其ID 如下:android:id="@android:id/list"
【讨论】:
view 在这行中来自哪里:list.addFooterView(view);?
view 是您要添加到ListView 的页脚的视图。