Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Maintaining scroll position of a ListView
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
DavidG  
View profile  
 More options Apr 7 2009, 10:36 am
From: DavidG <dgu...@gmail.com>
Date: Tue, 7 Apr 2009 07:36:10 -0700 (PDT)
Local: Tues, Apr 7 2009 10:36 am
Subject: Maintaining scroll position of a ListView
In my app, my main class extends ListActivity and calls a fillData()
function to reload the list whenever changes are made. I'm still
getting the hang of this, so I borrowed that concept from the Android
Notepadv1-Notepadv3 tutorials. Everything works great, however
whenever I need to change the list (remove an item, re-sort it, edit
an item), the ListView refreshes and loses its scroll position. The
scroll position is reset to the top after each fillData() call.

I saw the following thread a similar issue, but can't wrap my head
around the solution:
http://groups.google.com/group/android-developers/browse_thread/threa...

It appears to be resetting the scroll position to the top because I'm
using setListAdapter() each time in fillData(), setting it to a new
SimpleCursorAdapter. How can I get the list to "update in place",
where the scroll position is seamlessly maintained to the user? I
tried heading down the "items.changeCursor(cursor)" path, but that
didn't seam to do much for me. Any help would be appreciated. Here's
the code:

private void fillData(boolean sortOption) {
        Cursor itemCursor = mDbHelper.fetchAllItems(sortOption);
        startManagingCursor(itemCursor);

        String[] from = new String[] { DbA.KEY_ITEM, DbA.DESCRIPTION,
DbA.KEY_CHECKED };
        int[] to = new int[] { R.id.itemText, R.id.itemDescription,
R.id.content };

        SimpleCursorAdapter items = new SimpleCursorAdapter
(this,R.layout.item_row, itemCursor, from, to);
        items.setViewBinder(new ItemBinder());
        setListAdapter(items);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romain Guy  
View profile  
 More options Apr 7 2009, 2:00 pm
From: Romain Guy <romain...@google.com>
Date: Tue, 7 Apr 2009 11:00:01 -0700
Local: Tues, Apr 7 2009 2:00 pm
Subject: Re: [android-developers] Maintaining scroll position of a ListView
ListView handles that already. The problem is that you are creating a
new adapter every time you reload the data. That's not how you should
use ListView and its adapter. Instead of setting a new adapter (which
causes ListView to reset its state), simply update the content of the
adapter already set on the ListView. And the selection/scroll position
will be saved for you.

--
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »