I have tabView, displaying list in each tab. When I scroll in one tab, switch to another tab and return to previous tab, position is returned to the top instead of displaying pr
In listView.setOnItemClickListener
, use the saveLastPosition
method. And after listview.setAdapter(adapter);
call the getLastPosition
method
public void saveLastPosition(){
int position=listView.getLastVisiblePosition();
SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor=pref.edit();
editor.putInt("lastPosition",position);
editor.apply();
}
public void getLastPosition(){
int position=listView.getLastVisiblePosition();
SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(this);
int lastPosition=pref.getInt("lastPosition",position);
listView.setSelection(lastPosition);
}