Public classMainactivity extends Appcompatactivity {PrivateEditText EditText;PrivateTextView TextView; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main); EditText=(EditText) Findviewbyid (R.ID.XM); TextView=(TextView) Findviewbyid (R.ID.JL); Findviewbyid (R.ID.PG). Setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (view view) {Intent Intent=NewIntent (mainactivity. This, Main2activity.class); Intent.putextra ("Date", Edittext.gettext (). toString () +"Do you have faith in your classmates? "); Startactivityforresult (Intent,0); } }); Findviewbyid (R.id.exit). Setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (view view) {finish (); } });} @Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {Super.onactivityresult (Requestcode, ResultCode, data); Textview.settext (Data.getstringextra ("Date"));}} A second Java code Public classMain2activity extends Appcompatactivity {PrivateTextView JL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main2); JL=(TextView) Findviewbyid (R.ID.JL); Intent Intent=getintent (); Jl.settext (Intent.getstringextra ("Date"));} Public voidOnClick (view view) {Switch(View.getid ()) { CaseR.id.yes:back ("have a"); Break; CaseR.id.no:back ("No"); Break; }} Public voidBack (String content) {Intent Intent=NewIntent (); Intent.putextra ("Date", content); Setresult (1, intent); Finish ();}}
<linearlayout android:layout_width= "match_parent" android:layout_height= "0DP" Android:layout_weigh t= "1" android:orientation= "horizontal" > <button android:id= "@+id/pg" Android:lay Out_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "1" android:te xt= "@string/pg"/> <button android:id= "@+id/exit" android:layout_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "@string/exit"/> </LinearLayout></LinearLayout> <textview android:id= "@+id/jl" android:layout_width= "Match_pa Rent "android:layout_height=" 0DP "android:layout_weight=" 1 "android:gravity=" Bottom "android:t ext= "@string/jl" android:textcolor= "@color/colorprimarydark"/> <linearlayout android:layout_width= "Match_parent" android:layout_height= "0DP" android:layout_weight= "1" android:orientation= "Horizontal" > <button Android:id= "@+id/yes" android:layout_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "@string/yes"/> <button android:id= "@+id /no "android:layout_width=" 0DP "android:layout_height=" Wrap_content "Android:layout_weigh t= "1" android:text= "@string/no"/> </LinearLayout></LinearLayout>
Activity for Android March 5