2014-08-17
<!--first Page - <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"Android:layout_margintop= "126DP"Android:text= "parameter value returned" /> <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignparenttop= "true"Android:layout_alignright= "@+id/textview1"Android:text= "No return value Jump" /> <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignright= "@+id/button1"Android:layout_below= "@+id/button1"Android:text= "return value Jump" />
<!--- <button android:id= "@+id/ Button1 " android:layout_width=" Match_parent " android:layout_height = "Wrap_content" android:text= "button"/>
1 //first page of Java2 3 Public classMainactivityextendsactionbaractivity {4 PrivateButton bt1;5 PrivateButton bt2;6 PrivateTextView TV;7 8 @Override9 protected voidonCreate (Bundle savedinstancestate) {Ten Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.fragment_main); A - /** - * Two methods of jumping the * 1, no return value using startactivity (intent); - * 2, there are return results of the jump using Startactivityforresult (intent, requestcode); - */ -BT1 =(Button) Findviewbyid (r.id.button1); +BT2 =(Button) Findviewbyid (r.id.button2); -TV =(TextView) Findviewbyid (r.id.textview1); + ABt1.setonclicklistener (NewOnclicklistener () { at - @Override - Public voidOnClick (View v) { - //TODO Auto-generated method stubs -Intent Intent =NewIntent (mainactivity. This, change.class); -StartActivity (Intent);//The first of these methods in } - }); to +Bt2.setonclicklistener (NewOnclicklistener () { - the @Override * Public voidOnClick (View v) { $ //TODO Auto-generated method stubsPanax NotoginsengIntent Intent =NewIntent (mainactivity. This, change.class); - /** the * Second Method + * @intent: Intent Object A * @requestCode: The identity of the request, write here 1 the */ +Startactivityforresult (Intent, 1); - } $ }); $ } - - the /** - * Jump via Startactivityforresult, receive the returned dataWuyi * @requestCode: The identity of the request the * @resultCode: Receive the returned identity - * @data: Received data Wu */ - @Override About protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { $ //TODO Auto-generated method stubs - Super. Onactivityresult (Requestcode, ResultCode, data); - if(Requestcode==1 && resultcode==2) { -String content = Data.getstringextra ("Data"); A Tv.settext (content); + } the } -}
1 //second page of Java2 3 Public classChangeextendsactivity{4 PrivateButton bt;5 6 @Override7 protected voidonCreate (Bundle savedinstancestate) {8 //TODO Auto-generated method stubs9 Super. OnCreate (savedinstancestate);Ten Setcontentview (r.layout.change); One ABT =(Button) Findviewbyid (r.id.button1); -Bt.setonclicklistener (NewOnclicklistener () { - the @Override - Public voidOnClick (View v) { - //TODO Auto-generated method stubs -Intent data =NewIntent (); +Data.putextra ("Data", "Hello"); -Setresult (2,data);//the identity sent out +Finish ();//Close Page A } at }); - - } - -}
Display effect: