Let the ListView return to its original position
When you jump from one item in the ListView to another activity, the ListView may need to refresh (reload the data source), and the ListView will return to its original state, which is displayed starting with the first item. All we have to do is get it back to where it was.
//record the location of the current ListView Private intcurrent_listview_item_position = 0; @Override Public voidOnPause () {Super. OnPause (); Current_listview_item_position= Lvofcontact.getfirstvisibleposition ();//gets the first of the current ListViewSystem.out.println ("OnPause remembers the current position:" +current_listview_item_position); } @Override Public voidOnresume () {Super. Onresume (); Lvofcontact.setselection (current_listview_item_position);//back to the original positionSystem.out.println ("Scroll to the original location:" +current_listview_item_position); }//reload the data source in the ListView//call the method, you can go back to the original position.lvofcontact.setselection (current_listview_item_position);
Let the ListView return to its original position