Issue
the following lines are performed from onCreate() when activity is started:
textView.setText("abc");
checkBox.setChecked(true);
I can't understand why are these lines don't change the field values when orientation changes. the function is called, i can see it but the value are not changed.
thank you.
To add more details. When the activity starts and onCreate is performed first time both textView and checkBox are initialized ("abc" and true). Then I manually update the values of both fields in the device emulator and change screen orientation. OnCreate is called again. but this time the values are not updated (to "abc" and true) and remain unchanged.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkBox = (CheckBox) findViewById(R.id.checkBox1);
EditText editText= (EditText) findViewById (R.id.editText1);
editText.setText("abc");
checkBox.setChecked(true);
Toast.makeText(MainActivity.this, "in onCreate.", Toast.LENGTH_SHORT).show();
}
Solution
Your textView and checkBox are restored to their previous value later, in onRestoreInstanceState. You can read about this there:
Answered By - Rémi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.