java - Scroll position jumps on Android GridView -


I have a GridView in which several items are created by clicking on an item and creating a new detail view goes. Then the back button clicks on the user and returns to GridView . I want to keep the correct scroll state safe and I have completed that with the following code:

Creating GridView

  mArtistList = (GridView) artistsView.findViewById (R.id .gridview); Martistadaptor = new artist adapters (MCTXT); MArtistList.setAdapter (mArtistAdapter); / * * * The problem works fine here, but when the user touches; // Adapter Item Asynchronous as mArtistAdapter.registerDataSetObserver (New DataSetObserver) {@Override Public Zero onChanged () {// First select item becomes mArtistList.setSelection (installation of sActiveItem) GridView * Scroll Position Status where it * This line Without jumping * * / mArtistList.scrollBy (0, sActiveTop); super.onChanged ();}});  

The user clicks an item GridView

  sActiveItem = mArtistList.getFirstVisiblePosition (); // Vertical spacing (5dp to pixels) sActiveTop = (int) (5.0f * getResources () getDisplayMetrics () density ..); See first item = mArtistList.getChildAt (0); If (first itam! = Null) {sActiveTop - = firstItem.getTop (); }  

This works fine after the back position is pressed, the scrolling position is perfectly fine. The problem occurs when the user touches GridView . Moves the scroll to the place where the first visual object is at the top of the screen. How can I stop this jump?

I do not speak English as my native language, so it can be difficult to understand my explanation.

image here enter the details


Comments