Android Listview 深入研究 - 我使用一项活动还是多项活动?
我需要在我的 Android 应用程序中有一个 3 级“向下钻取”列表视图,并使用后退按钮来“向上”一级,并且想知道执行此操作的最佳实践是什么。数据将来自本地 SQLite 数据库。
根据我所读到的内容,我认为我有两个选择。
将列表视图的每个级别实现为单独的活动,并将每个活动作为传递在上一个级别/活动中选择的值的意图启动。
实现一个活动(可以调用自身,传递要显示的列表视图的值)并使用 switch 语句来处理为此级别行和数据适配器设置视图。
我愿意使用其中任何一个,尽管我稍微倾向于选项 2,因为我觉得为本质上相同的屏幕创建三个布局有点浪费。
任何有关哪种方法更好以及需要注意的问题的建议将不胜感激。
谢谢,
尼维兹
I need to have a 3 level 'drill down' listview in my Android app with the back button used to go 'up' a level and wanted to know what's the best practice to do this. The data will be coming from a local SQLite database.
From what I've read, I think I have two choices.
Implement each level of the listview as a seperate activity and start each activity as an intent passing the value that was selected at the previous level/activity.
Implement one activity (which can call itself passing the value of the listview to show) and use a switch statement to handle setting up the view for this levels row and data adapter.
I'm open to using either, although I'm slightly leaning towards option 2 as I feel creating three layouts for what are essentially identical screens is a bit of a waste.
Any suggestions on which method is better and anything to watch out for would be greatly appreciated.
Thanks,
NiVZ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也会选择选项 2。它更加整洁。
使用第一个选项,如果您想知道第三个列表中发生了什么,您将遇到将结果传播回第一个活动的问题。
您还考虑过使用
ExpandableListView
吗?默认情况下它只支持两个级别。I would go with option 2 as well. It is much neater.
With the first option you will have the problem of propogating the results back to the first activity in case you want to know what happened in the third list.
Also have you thought about using the
ExpandableListView
? by default it supports only two levels though..这实际上取决于三个屏幕的不同程度。如果它们只是内容不同(不同的图像、文本等),就像您的问题一样,那么您应该进行一项活动。如果 3 个屏幕之间的布局发生变化,至少使用多个布局 XML 文件。这将使以后更容易剥皮。
不过,这实际上取决于您,无论哪种方式都不会带来太大的性能优势。如果您觉得您的类的代码本质上是相同的,那么一个活动是合适的,否则,使用多个活动
It really depends on how different the three screens are. If they are only different in content (different image, text, etc) as it sounds like from your question, you should go with one activity. If you have changes in layout between the 3 screens, at least use multiple layout XML files. This will make it easier to skin later on.
It is really up to you though, there wouldn't be much performance benefits either way. If you feel the code of your class would be essentially the same, then one activity is appropriate, otherwise, use multiple activities