0

I am having an Adapter activity that extends CursorAdapter. So it has overriden methods like newView(), bindView(). I am updating the viewholder with textview values often. This works good in portrait mode. When turned to landscape mode, the values dont persist.

I know that you need to use onSaveInstanceState and onRestoreInstanceState. But these are for activities and mine is an Adapter class. What do I do in this case?

In a Fragment Activity, I have -

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putInt("Pos", mPosition);
    super.onSaveInstanceState(outState);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

In my Adapter class, I have th viewholder in bindview(). How do I access or use it in Fragment activity and save the values

Mark023
  • 105
  • 12
  • 1
    Possible duplicate of [Save data and change orientation](http://stackoverflow.com/questions/12214600/save-data-and-change-orientation) – buczek Jul 07 '16 at 15:14

1 Answers1

1

Your activity's onSaveInstanceState and onRestoreInstanceState needs to save all the variable the adapter needs persisted- either by directly saving them itself, or by adding a function to your adapter to save and restore and calling those.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127