ListFragment优于ListView或常规Fragment的优势 [英] Advantage of ListFragment over a ListView or normal Fragment

查看:128
本文介绍了ListFragment优于ListView或常规Fragment的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,其中包含一个菜单,菜单的左侧是textViews.当用户选择其中一个textViews时,它将在活动的其余区域中放置一个listView,占据屏幕的其他2 \ 3.当用户在页面的左侧菜单上触摸其他textView时,将打开另一个对应的listView项目.

I have an activity with a menu of items running down the left side that are textViews. when the user selects one of the textViews it will put a listView in the rest of the area of the activity taking up the other 2\3 of the screen. when the user touches a different textView on that left side menu of the page, it will open a different corresponding listView of items.

为此,我正在考虑在屏幕上放置一个大型列表视图.但是另一种方法是代替在活动中使用常规的listView,我可以在其中放置一个列表片段,然后在片段之间切换.

i was considering putting a large listview on the screen for this purpose. however one other way is instead of using a regular listView in the activity, i could put a list fragment in there and switch between fragments.

第三个选择是在其中放置一个片段,然后在该片段中放置一个listView.我以前从未使用过ListFragment.

The third choice is to put a fragment in there and put a listView inside of that fragment. I have never used ListFragment before.

考虑到方向不会改变,哪个是最好的计划?活动将被锁定为垂直/纵向.它将在平板电脑上运行,而不是在手机等较小的设备上使用.

which would be the best plan considering that there will be no orientation change? the activity will be locked in the vertical / portrait orientation. this will be running on a tablet, not used on smaller devices like phones.

我不知道我是否需要使用装载程序,因为列表不会很长,列表的内容只能是文本.

i don't know if i will need to use loaders, because the list will not be long and the contents of the list will be text only.

使用listFragment相比其他选择有什么优势吗?

is there any advantage to using listFragment over the other choices?

此活动的三个选择:

  1. 具有ListView的活动

具有ListFragment的活动

活动

推荐答案

ListFragment本质上是一个稍微专业化的Fragment,通过提供一些便利,它使处理Fragment布局中出现的ListView变得更加容易方法(例如getListView(),因此您无需自己搜索小部件,获取ListView的适配器的方法,等等).如果需要带ListViewFragment,请使用ListFragment.因此,最后是要在ListViewListFragment之间做出决定.

A ListFragment is basically a slightly specialized Fragment which makes handling a ListView present in the layout of the Fragment easier by offering some convenience methods(like getListView() so you don't need to search for the widget yourself, a method to get the adapter of the ListView etc). If you need a Fragment with a ListView, use a ListFragment. So in the end it's about deciding between a ListView and a ListFragment.

在这两个选项之间,考虑到您的情况,我会简单地使用ListView,因为它很简单.不需要Loader就是问题,因为您可以将ActivityLoaderManager用作ListView.

Between the two options, taking in consideration your scenario, I would simply use a ListViewbecause it's plain simple. The need of a Loader isn't a problem as you could use the LoaderManager of the Activity for the ListView.

但是,您没有提到应该如何处理后退"按钮.如果您想为用户提供浏览其选择的可能性,请使用Listfragment从系统中免费获取该内容.

However, you didn't mention how the BACK button should be handled. If you want to offer the user the possibility of navigating back through his choices use a Listfragment to get that for free from the system.

这篇关于ListFragment优于ListView或常规Fragment的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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