Android--activity recovering data entered by the user with EditText

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.