Permalink
Browse files

fixed a configuration-change bug

  • Loading branch information...
1 parent f62620b commit e6eb86e9a14c712ee9a797a7dd195976eef1b47b @commonsguy committed Nov 22, 2012
@@ -20,6 +20,7 @@
import java.util.ArrayList;
public class MainActivity extends Activity {
+ private static final String KEY_MIDDLE_CONTENTS="middleContents";
private static final String[] items= { "lorem", "ipsum", "dolor",
"sit", "amet", "consectetuer", "adipiscing", "elit", "morbi",
"vel", "ligula", "vitae", "arcu", "aliquet", "mollis", "etiam",
@@ -43,6 +44,9 @@ public void onCreate(Bundle savedInstanceState) {
SimpleListFragment.newInstance(items))
.commit();
}
+
+ middleFragment=
+ (SimpleListFragment)getFragmentManager().findFragmentById(R.id.middle);
}
@Override
@@ -56,10 +60,22 @@ public void onBackPressed() {
}
}
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ outState.putStringArrayList(KEY_MIDDLE_CONTENTS, middleContents);
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle inState) {
+ middleContents=inState.getStringArrayList(KEY_MIDDLE_CONTENTS);
+ }
+
void onListItemClick(SimpleListFragment fragment, int position) {
if (fragment == middleFragment) {
((Button)root.getRightView()).setText(middleContents.get(position));
-
+
if (isLeftShowing) {
root.hideLeft();
isLeftShowing=false;
@@ -20,6 +20,7 @@
import java.util.ArrayList;
public class MainActivity extends FragmentActivity {
+ private static final String KEY_MIDDLE_CONTENTS="middleContents";
private static final String[] items= { "lorem", "ipsum", "dolor",
"sit", "amet", "consectetuer", "adipiscing", "elit", "morbi",
"vel", "ligula", "vitae", "arcu", "aliquet", "mollis", "etiam",
@@ -43,6 +44,9 @@ public void onCreate(Bundle savedInstanceState) {
SimpleListFragment.newInstance(items))
.commit();
}
+
+ middleFragment=
+ (SimpleListFragment)getSupportFragmentManager().findFragmentById(R.id.middle);
}
@Override
@@ -56,6 +60,18 @@ public void onBackPressed() {
}
}
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ outState.putStringArrayList(KEY_MIDDLE_CONTENTS, middleContents);
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle inState) {
+ middleContents=inState.getStringArrayList(KEY_MIDDLE_CONTENTS);
+ }
+
void onListItemClick(SimpleListFragment fragment, int position) {
if (fragment == middleFragment) {
((Button)root.getRightView()).setText(middleContents.get(position));

0 comments on commit e6eb86e

Please sign in to comment.