如何在活动中使用getListView()? [英] how to use getListView() in Activity?

查看:180
本文介绍了如何在活动中使用getListView()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ListActivity是可以使用 this.getListView()addFooterView(footerView);

In ListActivity is can use this.getListView().addFooterView(footerView);

但如果我用的活动就不能使用 this.getListView()

but if I use Activity it can't use this.getListView()

我该怎么办?

推荐答案

当你使用活动 your_layout.xml 作为你的活动内容查看。因此,的ListView your_layout.xml 应该湾

Whenever you use Activity you set your_layout.xml as your Activity's ContentView. So the ListView should b in your_layout.xml.

这ListView控件应该在XML文件中定义说,一个id属性:(机器人:ID =@ + ID /列表)。 你得到你的的ListView 对象的某些事情是这样的:

That ListView should have an id attribute defined in xml file say: (android:id="@+id/list"). You get your ListView object some thing like this way:

setContentView(R.layout.your_layout);
ListView list = (ListView)findViewById(R.id.list);
list.addFooterView(view);

而当你使用 ListActivity 你得到你的的ListView 通过调用方法

And when you use ListActivity you get your ListView by calling method

ListView list = getListView(); // OR you can do
ListView list = (ListView)findViewById(android.R.id.list);  //consider the android prefix..

和请注意,虽然定义任何 layout.xml ListActivity ,你将有一个在布局具有这样的ID的ListView 机器人:ID =@机器人:ID /列表

and please note that while defining any layout.xml for ListActivity you would have a ListView in your layout having id of something like this: android:id="@android:id/list"

这篇关于如何在活动中使用getListView()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆