Description
In the horizontal screen input content, after the activity destroys, that is, after the horizontal screen, obtains the user input content
Steps:
1. Define the ID of the edittext in the XML page
2. Save user-entered data with Onsaveinstancestate
(1) Tune the parent class
(2) Use Findviewbyid to find and get an instance of the view (the parent class of the view all controls, and then cast again)
(3) Find the instance, get the text content: Convert to string get
(4) Save the content and put it.
3. Recovering data with Onrestoreinstancestate
(1) Get Data get first
(2) Operation View instance find
(3) Set the contents of the text box
Excise1.xml
< EditText Android:layout_width = "Wrap_content" android:layout_height= "Wrap_content" android:textsize= "40DP" android:id= "@+id/ett" />
Excise1.java
//recovering data entered by the user with EditText//get data to save user input//define member variables for convenienceString edd = "EditText"; @Overrideprotected voidonsaveinstancestate (Bundle outstate) {Super. Onsaveinstancestate (outstate); //1. Use the ID to find and get an instance of the view (the parent class of the view all controls, and then cast again)EditText et =(EditText) Findviewbyid (R.id.ett); //2. Find the instance, get the text content: Convert to string GetString str = Et.gettext (). toString ();//Local VariablesLOG.E ("Tag", "Get user input" +str); //3. Save the captured content to putOutstate.putstring (EDD,STR);//outstate.putstring ("EditText", str); } //save data to recover user input@Overrideprotected voidonrestoreinstancestate (Bundle savedinstancestate) {Super. Onrestoreinstancestate (savedinstancestate); //recovering user-entered data//get the data get firstString str = savedinstancestate.getstring (EDD);//savedinstancestate.getstring ("EditText");LOG.E ("tag", "Recover user-entered content" +str); //Manipulating View Instances//restores the contents of the input box (set) SetEditText et =(EditText) Findviewbyid (R.id.ett);//For convenience definable global variables EditText et et.settext (str); }
Android--activity recovering data entered by the user with EditText