Android 3.0 Loader 永远存在
我想要实现的是拥有一个 ListFragment,它显示从外部源加载的数据。我想使用 Android 3.0 SDK 来实现此目的,并尽可能接近本机用户体验。
事实上,一切正常,我正在调用 getLoaderManager().initLoader(0, null, this) 在 ListFragment 的 onActivityCreated()
中。 我也实现了 onCreateLoader、onLoadFinished 和 onLoaderReset,但问题是,即使调用了 onLoadFinished 并且我得到了所有结果,加载程序仍然保留并且不会消失。
我尝试调用 loader.abandon()
、loader.stopLoading()
和 getLoaderManager().destroyLoader(0)
。但是加载程序仍然主动可见并显示其动画。
我遇到的问题还在于所有示例都只能与 CursorLoader 一起使用,也许我误解了这里有一个加载器的整个想法。事实上,我还必须编写自己的 Loader 实现,它扩展了 AsyncLoaderTask,但它与 CursorLoader 的功能基本相同。
那么也许还有其他更适合这项任务的东西?说实话,我对 Android 开发一无所知:)
What I want to achieve is having a ListFragment which displays data loaded from an external source. I want to use the Android 3.0 SDK for this purpose and come as close to the native user experience as possible.
In fact everything works fine, I am calling getLoaderManager().initLoader(0, null, this)
in onActivityCreated()
of the ListFragment.
I implemented onCreateLoader, onLoadFinished and onLoaderReset as well but the problem is that even though onLoadFinished is called and I get all the results the loader stays and will not go away.
I tried calling loader.abandon()
, loader.stopLoading()
and getLoaderManager().destroyLoader(0)
.However the loader is still actively visible and displaying its animation.
The problem I had is also that all examples are only working with a CursorLoader and maybe I missunderstood the whole idea of having a loader here. In fact I also had to write my own Loader implementation which extends AsyncLoaderTask but it is mostly identical to what CursorLoader does.
So maybe there is something else suited better for this task? To be honest I have absolutely no clue about Android development :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是我正在调用 getListView().setAdapter(...) 而不是 setListAdapter(...)。
Probelm is I was calling getListView().setAdapter(...) instead of setListAdapter(...).