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

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

问题描述

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

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

但是如果我使用 Activity 它就不能使用 this.getListView()

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

我该怎么办?

推荐答案

每当您使用 Activity 时,您都将 your_layout.xml 设置为您的 ActivityContentView.所以 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 属性说:(android:id="@+id/list").您可以通过以下方式获取 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 时,您会通过调用方法

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..

并且请注意,在为 ListActivity 定义任何 layout.xml 时,您的布局中将有一个 ListView 具有类似这样的 id: android:id="@android:id/list"

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天全站免登陆