I have a GridView and when someone scrolls down the screen and selects
an item, I update the GridView with new contents and set the selection
to 0 so that the first item in the updated view is being shown. For
example: show the contents of a directory, scroll down, select a
directory, update the UI with the new directory's contents and show
the first file.
The problem is that the UI is jerky during this process. What I see
when the GridView is updated is that first the new contents are loaded
into the UI at the old scrolled down position and then the UI jerks to
the first position.
What the problem appears to be is that UI gets updated when the
contents are updated and then there is a 2nd round of updating when
the selection is set to 0.
Is there a way to avoid the 1st round up UI updating? Alternatively,
is there a way to set the selection to 0 before the contents get
updated? I've tried a variety of solutions but either the set
selection gets broken or I have jerking UI.
Pseudo code:
// This is called when the user clicks on an item in the GridView
void updateUI()
{
myAdapter.setNotificationOnChange( false ); // Try to turn of
updating the UI
myAdapter.clear();
myAdapter.addAll( theNewData );
myAdapter.notifyDataSetChanged()
myGridView.clearFocus(); // Someone recommended this online,
doesn't help
myGridView.post( new Runnable() {
@Override
public void run() { myGridView.setSelection( 0 ) }
} );
};
Here, I have my own adapter class (myAdapter is an instance of that
class). For performance reasons, the getView implementation already
has implemented the holder pattern (so findViewById is not excessively
called). This reduced the time of the UI jerkiness but didn't
eliminate it.
Importantly, if I Log.d statements in the updateUI, the Runnable.run,
and in the MyAdapter.getView, I see the followinging:
getView position 12 // These are from the user scrolling down
in the old contents
getView position 13
getView position 14
getView position 15
updateUI start // User clicked on an item, new contents
loaded in
updateUI end
getView position 12 // UI updates with new contents at WRONG
position/selection
getView position 13
getView position 14
getView position 15
Runnable.run, selection set to 0
getView position 0 // UI finally updates to correct position/
selection
getView position 1
getView position 2
getView position 3
I've attempted variations on the updateUI code such as doing a
myGridView.post() of the myAdapter.notifyDataSetChanged() so that it
occurs _after_ the myGridView.setSelection(0), but this only changed
details of how the jerkiness looks and does not make it go away.
Other variations of what is posted, when things are posted, and the
order the methods are called either don't help the jerkiness or
setSelection simply fails to work.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en