Android Interface Jump

Source: Internet
Author: User

Interface Design Code


<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/activity_tiaozhuan"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "@android: Color/holo_orange_dark"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"android:orientation= "Vertical"Tools:context= "Hello.jmtiaozhuan.TiaozhuanActivity" ><EditText android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_margintop= "150DP"Android:hint= "@string/edittextname"Android:textcolorhint= "#f0ff"android:gravity= "Center"Android:textcolor= "#00ffee"Android:id= "@+id/shuru"/> <LinearLayout android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" > <Button android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "@string/button1"style= "@style/text"Android:onclick= "OnClick"Android:id= "@+id/button1"/> <Button android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "@string/button2"style= "@style/text"Android:id= "@+id/button2"/> </LinearLayout> <TextView android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "@string/textviewname"android:gravity= "Center"Android:id= "@+id/show"Android:textcolor= "#33ff00"style= "@style/text"Android:onclick= "OnClick"/></linearlayout>

The effect is as follows


String file code

<resources> <string name= "app_name" >JMtiaozhuan</string> <string name= "Button1" > Click to enter evaluation </string> <string name= "Button2" > Exit </string> <string name= "Edittextname" > Please enter your name </string> <string name= "Textviewname" > Output evaluation results </string> <string name= "Button3" > have </string> <string name= "Button4" > No </string></resources>
Key Content Button monitoring
Btbutton2.setonclicklistener (NewView.onclicklistener () {@OverridepublicvoidOnClick (View v) {if(Btbutton2.isclickable ()) {Toast.maketext (mainbackactivity). This, "Press the exit button again", Toast.length_long). Show ();//If the Exit button is clicked, the text is displayed and the Exit button is pressed againBtbutton2.setonclicklistener (NewView.onclicklistener () {@Override publicvoidOnClick (View v) {if(Btbutton2.isclickable ()) {mainbackactivity. This. Finish ();//once again, if you press the Exit button again, the entire interface will be closed.                        }                    }                }); }        }    });

The most important data transfer1 Transferring data to a sub-interface for the main boundary
if (Textutils.isempty (Etshuru.gettext (). toString ())) {Toast.maketext (mainbackactivity. This, "input name cannot be empty", Toast.length_short). Show ();    // If you do not enter a name, click Enter to evaluate it will show return  =new Intent (mainbackactivity.  this, jiemianactivity.class); Mintent.putextra ("name", Etshuru.gettext (). toString (). Trim () + "classmate: Do you have confidence in learning Android?");      // Pass the name string to the sub-interface, trim () to remove both sides of the space Startactivityforresult (mintent, 1000);
2 sub-interface to receive data
Intent Intent = getintent (); TextView tvshow=(TextView) Findviewbyid (r.id.show); String name=intent.getstringextra ("name");    // receives the name Data tvshow.settext (name) passed over by the main interface ;
3 Sub-interface return data
void Ruturn () {Intent Intent=new Intent (this, mainbackactivity.class); Button Btnbutton3=(Button) Findviewbyid (R.id.button3); String name=btnbutton3.gettext (). toString (); Intent.putextra ("name", "Evaluation content returned as:" +name); Finish ();}
4 main interface accepts return data
void onactivityresult (intint  resultcode, Intent data) {Super.onactivityresult ( Requestcode, ResultCode, data);      //  If (Requestcode = = && (ResultCode = = 1001 | | resultcode = = 1002)) {    // make the main interface The requestCode1000 of the polygon and the resultCode1001 or 1002 of the sub-interface are compared TextView tvshow =Data.getstringextra ("name");    // receive the "name" data passed by the sub-interface Tvshow.settext (result);}}

Android Interface Jump

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.