ExpandableListFragment 与 LoaderManager 兼容包
我想让我的 ExpandableListActivity 与 Honeycomb 兼容。 我想知道为什么兼容包没有 ExpandableListFragment。
有没有办法让 ExpandableListView 与普通的 Fragment 类一起工作? 如何使用 LoaderManager 加载游标?
I want to make my ExpandableListActivity compatible with Honeycomb.
I am wondering why there is no ExpandableListFragment for the Compatibility Package.
Is there a way to make ExpandableListView work with the normal Fragment class?
How do I load the Cursors with the LoaderManager?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也有同样的问题。我没有找到解决方案,所以我决定自己基于 android.support.v4.app.ListFragment (兼容性 API)和 API 级别 8 的 android.app.ExpandableListActivity 的组合来实现 ExpandableListFragment,所以这应该兼容API级别< 11.
不过,我无法回答您关于 Cursors 和 LoaderManager 的问题。
关于我的 ExpandableListFragment 版本需要注意的一件事是,您必须自己从封装活动的 oncontentchanged() 方法定义中调用其方法 onContentChanged() ,否则不会有任何侦听器附加到列表项。
ExpandableListFragment 的源代码(在 android.support.v4.app 的本地包副本中,将其命名为您想要的名称):
I had the same problem. I didnt find a solution for this, so I decided to implement the ExpandableListFragment myself based on a combination of the android.support.v4.app.ListFragment (Compatibility API) and the android.app.ExpandableListActivity from API level 8, so this should be compatible with API level < 11.
I dont have an answer to your question about Cursors and LoaderManagers, though.
One thing to note about my version of the ExpandableListFragment, you have to call its method onContentChanged() yourself from the oncontentchanged()-method-definition of your encapsulating activity, or else there wont be any listener attached to the listitems.
The sourcecode for ExpandableListFragment (in a local package-copy of android.support.v4.app, name it what you want):
不确定是否有人可以从 arne.jans 的帖子中获取代码,但我不能,因为 mListContainer 始终为空。每次我们调用 setListShown 方法时,ensureList() 实际上都会被调用。
因此,我使用了与 arne.jans 相同的想法,结合了 ListFragment 和 ExpandableListActivity 中的代码(从 http://grepcode.com/ 下载)。我终于让它发挥作用,并认为这对其他人可能有帮助。下面是代码:
希望它有时能拯救你。
Not sure if anyone can get the code working from the post from arne.jans but I couldn't because the mListContainer is always null. The ensureList() is actually invoked every time we go to setListShown method.
So, I used the same idea as arne.jans's, combining the code from ListFragment and ExpandableListActivity (downloaded from http://grepcode.com/). I finally got it to work and thought this could be helpful for others. Below is the code:
Hope it saves you sometimes.
我想要尽可能少的改变;当已经使用 ExpandableListActivity 时,无需使用上面的片段实现,只需将 ExpandableListActivity 的代码复制到自己的应用程序中,更改内部 R.* 资源引用以使用对应的公共命名空间,并将类更改为从 FragmentActivity 继承。
I wanted the least amount of changes possible; instead of using the fragment implementation above, when already using a ExpandableListActivity, one can simply copy the code of ExpandableListActivity into one's own application, change the internal R.* resource references to use the counterpart public namespace, and change the class to inherit from FragmentActivity.