Activity for Android March 5

Source: Internet
Author: User

 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

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.