同时保持在ListView中滚动位置更新SimpleCursorAdapter [英] Update SimpleCursorAdapter while maintaining scroll position in ListView

查看:297
本文介绍了同时保持在ListView中滚动位置更新SimpleCursorAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:我的ListView控件将它的滚动位置时,我通过它(定制)SimpleCursorAdapter更新其内容的顶部。我想在ListView保持其滚动位置时更新。

My problem: My ListView resets its scroll position to the top whenever I update its contents through its (customized) SimpleCursorAdapter. I would like the ListView to maintain its scroll position when updated.

我开始通过创建一个新的适配器实例每次使用 ListView.setAdapter(),但根据<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/2e425f0cca0c0e8b?pli=1">this讨论我应该更新重置它的适配器来代替。我无法找到一个方法来做到这一点的SimpleCursorAdapter的正常工作。

I started out by creating a new adapter instance every time and using ListView.setAdapter(), but according to this discussion I should be updating the adapter instead of resetting it. I can't find a way to do this for SimpleCursorAdapter that works correctly.

这里有一些事情我已经试过,省略方法参数:
- SimpleCursorAdapter.changeCursorAndColumns()用新鲜的光标成功更新的适配器,但仍重置滚动位置
- SimpleCursorAdapter.changeCursor()作用相同
。 - SimpleCursorAdapter.swapCursor()不可用,直到11 API,而我开发的API 8
- SimpleCursorAdapter.notifyDataSetChanged()不更新ListView控件。 (也许还有另外一个步骤我失踪。)
- ListView.invalidate()不更新的ListView
。 - SimpleCursorAdapter.requery()使ListView的空白,是德precated
。 - 我熟悉的 ListView.setSelection()解决方案,但我不希望当它被更新了我的ListView来移动。此捕捉它在列表中的位置上。

Here are some things I've tried, omitting the method arguments:
- SimpleCursorAdapter.changeCursorAndColumns() with a fresh cursor successfully updates the adapter but still resets the scroll position.
- SimpleCursorAdapter.changeCursor() acts the same way.
- SimpleCursorAdapter.swapCursor() isn't available until api 11, and I am developing for api 8.
- SimpleCursorAdapter.notifyDataSetChanged() does not update the ListView. (Maybe there is another step I'm missing.)
- ListView.invalidate() does not update the ListView.
- SimpleCursorAdapter.requery() makes the ListView blank, and is deprecated.
- I'm familiar with the ListView.setSelection() solution, but I don't want my ListView to move at all when it is updated. This snaps it to a position in the list.

这似乎应该是一个共同的和简单的问题。有没有人处理呢?

This seems like it should be a common and simple problem. Has anybody dealt with it?

推荐答案

我有一个类似的问题:我的CursorAdapter重置滚动位置,只要游标的内容,改变了

I've had a similar problem: My CursorAdapter reset the scroll position whenever the contents of the cursor changed.

我不知道,其实我的数据变化,每次设定一个新的列表适配器。我以为光标本人将通知有关更改适配器到它的内容,但在我的情况下,它是触发LoaderManager.LoaderCallbacks.onLoadFinished的的ContentProvider()在我的ListFragment。在该回调我现在用CursorAdapter.changeCursor(),而不是创建一个新的适配器,一切工作就好了。

I didn't realize that I actually did set a new list adapter each time the data changed. I thought the cursor himself would notify the adapter about changes to it's content but in my case it is the ContentProvider that triggers LoaderManager.LoaderCallbacks.onLoadFinished() in my ListFragment. In that callback I now use CursorAdapter.changeCursor() instead of creating a new adapter and everything works just fine.

我希望这可以帮助解决你的问题。

I hope this helps solving your problem.

这篇关于同时保持在ListView中滚动位置更新SimpleCursorAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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