Description
Jump page, and the first page of the EditText input data through the button to the second page edittext display, click on the second page of the
Return button buttons to return to the first page (changing the contents of EditText on the second page will be transmitted to the EDITTEXT display on the first page)
--a way to return values
1. Set the ID for the first page edittext and button
2. Set button's click-Listen
(1) Get the view instance and find the EditText by EditText ID
(2) Get the content and convert it into textual form
GetText (). ToString ()
(3) Set Intent (intent) to tell the second page, I'm going to jump
Intent in = new Intent (this,excise2.class);
(4) At the same time, the input text content is stored and passed through intent.
In.putextra ("Myet", str);
(5) Start jumping to distinguish common ways
Startactivityforresult (in,1);
3. Accept the page with EditText receive
(1) Set ID to accept page edittext and button
(2) Create a second page
public class Excise2 extends Activity {
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.LAYOUT.EXCISE2);
(3) Receiving intent intent get
Intent in = Getintent ();
(4) Take the data that is stored get get
String str = In.getextras (). getString ("Myet");
(5) Display data
Manipulating View Instances
EditText mytv= (EditText) Findviewbyid (R.id.jieshouzhi);
Restores the contents of the input box (set) set
Mytv.settext (str);
4. Set the button's tap to listen
(1) Store the returned data with intent
EditText ett = (EditText) Findviewbyid (R.id.jieshouzhi);
(2) Set the return data
Set the ResultCode first, then set the intent to store the data
Intent in = new Intent ();
Setresult (Result_ok,in.putextra ("MyTV", Ett.gettext (). toString ()));
(3) Close
Finishi ();
5. Receive the returned value on the first page
(1) overriding callback methods
Onactivityresult (int requestcode, int resultcode, Intent data)
(2) Plus judging conditions
(3) Get the returned information first
String str = Data.getextras (). getString ("MyTV");
(4) Display
EditText ett = (EditText) Findviewbyid (R.id.ett);
5) Value Setting set
Ett.settext (str);
Excise1.xml
<EditTextAndroid:layout_width= "200DP"Android:layout_height= "Wrap_content"android:textsize= "40DP"Android:id= "@+id/ett" /> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Pass value to third page"android:textsize= "40DP"Android:id= "@+id/chuanzhi"Android:layout_margintop= "100DP"Android:onclick= "Clickcz" />
Excise1.java
Public voidClickcz (view view) {//toast static methods are called directly with the class name and do not need to be instantiated//Build A Toast Method instance method call method chainToast.maketext ( This, "This is triggered by mouse click monitoring", Toast.length_long). Show (); //get the information you want to pass//Get View instanceEditText ett =(EditText) Findviewbyid (R.id.ett); //Get contentString str =Ett.gettext (). toString (); //Jump Diversion IntentIntent in =NewIntent ( This, Excise2.class); //Store content via intent//The Extra extension is actually a hashmap, and the limit PutExtra is a bundleIn.putextra ("Myet", str); //start jump no return value of the notation//startactivity (in); //start jumping with the return value of the notation//starting mode, with return value//The first parameter of intent//second parameter Requestcode request code Startactivityforresult (in,1); } //handling the Listener (callback method) for returning information//listening for all returned information//there must be requestcode to distinguish which request is returned by@Overrideprotected void Onactivityresult(intRequestcode,intResultCode, Intent data) { Super. Onactivityresult (Requestcode, ResultCode, data); if(Requestcode ==1) if(ResultCode = =RESULT_OK) { //get the returned information firstString str = Data.getextras (). getString ("MyTV"); //ShowEditText ett =(EditText) Findviewbyid (R.id.ett); //Value Setting setEtt.settext (str); } Else{Toast.maketext ( This, "The returned content has errors", Toast.length_long); } }
Excise2.xml
<EditTextAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Excise2 third page"android:textsize= "40DP"Android:id= "@+id/jieshouzhi" /> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_margintop= "250px"Android:text= "With return worth returning"android:textsize= "40DP"Android:id= "@+id/clickec4"Android:onclick= "CLICKEC4"/>
Excise2.java
Packagecom.example.chenshuai.excise;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.EditText;/*** Created by Chenshuai on 2016/3/20.*/ Public classExcise2extendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.LAYOUT.EXCISE2); //Receive Information//1. Acceptance of the intention to pass overIntent in =getintent (); //2. Fetching DataString str = In.getextras (). getString ("Myet"); //3. Where is the display//Manipulating View InstancesEditText mytv=(EditText) Findviewbyid (R.id.jieshouzhi); //restores the contents of the input box (set) SetMytv.settext (str); } Public voidClickec4 (View v) {//store return data with intentEditText ett =(EditText) Findviewbyid (R.id.jieshouzhi); //set the return data//set the ResultCode first, then set the intent to store the dataIntent in =NewIntent (); Setresult (Result_ok,in.putextra ( "MyTV" , Ett.gettext (). toString ())); Finish (); }}
android--Return of activity jumps (no return value and return value)--there is a return value