开发者

cursor position in a listview lost when move away from activity

I populate ListView with data from a Sqlite database using custom CursorAdapter.

When user moves away from my activity and comes back later I loose the position in my cursor and the ListView is positioned to the first item again.

When skipping startManagingCursor() it works as expecte开发者_如何学运维d. How do I work around this?

Here is a code snippet called OnCreate():

cursor  = db.getAll();      
startManagingCursor(cursor);
myAdapter = new MyAdapter(listview.getContext(), cursor, true);
listview.setAdapter(myAdapter);


LatinSuD is correct, you'll want to store the position in the bundle. The managed cursor is requeried when the activity becomes active again so you'll lose your spot. You can look at the notepad3 tutorial for an example of saving state information. http://developer.android.com/resources/tutorials/notepad/notepad-ex3.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜