Hi,
How can I maintain the position of my ListView in my activity when I go to another activity (by launching another intent) and then come back (press the back button)?
Thank you.
Hi,
How can I maintain the position of my ListView in my activity when I go to another activity (by launching another intent) and then come back (press the back button)?
Thank you.
@Override
protected void onPause()
{
// Save scroll position
SharedPreferences preferences = context.getSharedPreferences("SCROLL", 0);
SharedPreferences.Editor editor = preferences.edit();
int scroll = mListView.getScrollY();
editor.put("ScrollValue", scroll);
editor.commit();
}
@Override
protected void onResume()
{
// Get the scroll position
SharedPreferences preferences = context.getSharedPreferences("SCROLL", 0);
int scroll = preferences.getInt("ScrollView", 0);
mListView.scrollTo(0, scroll);
}
You should use onSaveInstanceState
to store the scroll position and then use either onCreate
or onRestoreInstanceState
to restore it.