0
votes

I have a gridview which is populated with 10 images, when I scroll down to the last item and change the data completely, this way:

gridAdapter.values.clear();
gridAdapter.notifyDataSetChanged();

and add completely new set of 10 images.

The problem is, by default the gridView is scrolled to the bottom most item, may be because the previous scroll position was that. Its same like you scroll through a list -> click on item -> click back and the browser tries to scroll to the previous scroll position.

How can I show the top more item, instead of this behavior.

2
Is your goal to have like infinite grid with only 10 items in adapter max and user able to scroll it without noticing any difference?Niko
No, I want the gridview to stay on top most item, when ever I clear the data and add new data.user1537779
Have you tried scrollTo(0) after setting new data?Niko
There is no such funtionuser1537779
GridView should have that methodNiko

2 Answers

0
votes

Try this:

int pos = gridview.getFirstVisiblePosition(); 
gridview.smoothScrollToPosition(pos);

When you are returning from another activity.

0
votes

When in bottom you can call:

gridView.setAdapter(null);
gridView.setAdapter(prevAdapterWithNewItems);

However this doesn't abort user scrolling or fling effect.