Android的 - 活动与ListActivity - 哪一个应该我的活动类扩展? [英] Android - Activity vs. ListActivity - Which one should my activity class extend?

查看:114
本文介绍了Android的 - 活动与ListActivity - 哪一个应该我的活动类扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习在Android的开发,并有更多的普遍问题:如果我有一个使用列表和其他一些意见,布局我应该使用的活动或ListActivity我的活动类

I've been learning to develop in Android and had more of a general question: If I have a layout that uses a list and some other views, should I be using Activity or ListActivity for my activity class?

我知道,ListActivity将可能使事情变得更容易覆盖列表中特定的事件,但没有任何其他的优势,使用一个ListActivity在活动?如果我想在未来的布局更改为一个GridView?难道是任何增加/减少的痛苦更改类'code?

I know that ListActivity will probably make things easier to override list-specific events, but is there any other advantage to using a ListActivity over Activity? What if I wanted to change the layout in the future to a GridView? Would it be any more/less of a pain to change the class' code?

我只是好奇在这方面的最佳做法,什么好处带来,所以任何回答将是有益的:)

I was just curious about "best practices" in this regard and what the benefits entail, so any answer would be helpful :)

巴拉

推荐答案

我会使用一个 ListActivity ,因为它给你很多的快捷方式,使操作更容易,保持你的code更具可读性。

I'd use a ListActivity since it gives you a lot of shortcut methods to make things easier and keep your code more readable.

例如,你得到的<一个href="http://developer.android.com/reference/android/app/ListActivity.html#onListItemClick%28android.widget.ListView,%20android.view.View,%20int,%20long%29"><$c$c>onListItemClick()方法 它,只要你点击它可以省掉创建一个单独的侦听器。一个项目叫做

For example, you get the onListItemClick() method which is called whenever you click a item which saves you from creating a separate listener.

如果你想改变的 ListActivity 你还可以使用<一个布局href="http://developer.android.com/reference/android/app/Activity.html#setContentView%28int%29"><$c$c>setContentView()方法从活动 。只要有一个的ListView 名为 @android:ID /列表放在你的查看 ListActivity 仍然可以工作。

If you want to change the layout of a ListActivity you still can with setContentView() method from Activity. As long as there is a ListView called @android:id/list somewhere in your View the ListActivity will still work.

如果你仍然不知道,你总是可以看看<一href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/app/ListActivity.java;h=19b99c874afbaa1ca9a0bf2a0ae01ee064bb6b43;hb=HEAD">source $ C $下 ListActivity 并看到它没有做比让你的生活那么多其他的更容易一些。

If you're still not sure, you could always look at the source code for ListActivity and see that it doesn't do all that much other than make your life a little easier.

这篇关于Android的 - 活动与ListActivity - 哪一个应该我的活动类扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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