Use intent and bundle objects in antivity1 to switch activity and pass data
Button Button01 =(Button) Findviewbyid (R.id.button1); Button01.setonclicklistener (NewButton.onclicklistener () { Public voidOnClick (View v) {EditText et=(EditText) Findviewbyid (R.ID.EDITTEXT1); DoubleEditText1 = Double.parsedouble (Et.gettext (). toString ());//Take valueString Choose= ""; RadioButton Rg1= (RadioButton) Findviewbyid (R.id.radiobutton);//check box value if(Rg1.isclickable ()) {Choose /c7>= "M"; } ElseChoose = "F"; Intent Intent=NewIntent (); Intent.setclass (ChangeTest01. This, ChangeTest02.class);//The activity was changedBundle Bundle=NewBundle ();//data transfer for activityBundle.putdouble ("Edit1", EDITTEXT1);//Pass the data within the quotation marks, followed by the pass valueBundle.putstring ("Choose", choose); Intent.putextras (bundle); //assign the bundle object to Intert;StartActivity (Intent);//Call another activity } } );
And the data in the bundle object is accepted in the Activity2
Bundle bundle = This. Getintent (). Getextras ();//get the Bundle object in intentString Choose= Bundle.getstring ("choose");//get the data from the bundle object DoubleEdit1 = bundle.getdouble ("Edit1"); String Choosetext= ""; if(Choose.equals ("M") ) {Choosetext= "A"; }Elsechoosetext= "B"; TextView TextView1=(TextView) Findviewbyid (R.ID.TEXTVIEW1); Textview1.settext (Choosetext); TextView TextView2=(TextView) Findviewbyid (R.ID.TEXTVIEW2); Textview2.settext (string.valueof (edit1)); //Double Turn string
It is important to note that there is more than one activity, so we need to decide the main program;
In the Androidmainfest.xml
Set up
<activity android:name= ". ChangeTest01 " android:label=" @string/title_activity_change_test01 "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= " Android.intent.category.LAUNCHER "/> </intent-filter> </activity> <activity android:name= ". ChangeTest02 " android:label=" @string/title_activity_change_test02 "> </activity>
changetest01 because entry point was added so start from it first
Unlike Esplice in Android studio, you don't need to add activity manually.
If necessary, just change the main program in Androidmanifest.
Activity switching and data transfer