Android simple application test water and real machine testing problem solving

Source: Internet
Author: User

Hit the book on a wave of simple Android applications, mainly through the age of sex to give marriage advice, PO code;

. java files:

PackageCom.example.admin.experiment;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.EditText;ImportAndroid.widget.TextView;PublicClass MainactivityExtendsappcompatactivity {PrivateButton Btndosug;PrivateEditText Edtage,edtsex;PrivateTextView Txtresult; @OverrideProtectedvoidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Setupviewcomponent (); }PrivatevoidSetupviewcomponent () {btndosug=(Button) Findviewbyid (R.ID.BTNDOSUG); Edtage=(EditText) Findviewbyid (r.id.edtage); edtsex=(EditText) Findviewbyid (r.id.edtsex); txtresult=(TextView) Findviewbyid (R.id.txtresult); Btndosug.setonclicklistener (Btndosugonclick); }Private Button.onclicklistener btndosugonclick=NewButton.onclicklistener () {/*** Called when a view has been clicked. * *@paramV The view that is clicked.*/@OverridePublicvoidOnClick (View v) {String sex=Edtsex.gettext (). toString ();int age=Integer.parseint (Edtage.gettext (). toString ()); String result= "Result";if (Sex.equals ("Male"))if (Age<28else if (Age>33) result+= "Marry quickly" else result+= "Start looking for the object" else if (Age<25) result+= "Not urgent" else if (Age>30) result+= "Marry quickly" else result+= "Start looking for the object"  

. xml file:

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutXmlns:android= "Http://schemas.android.com/apk/res/android"Android:orientation= "Vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"><TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Gender"Android:id= "@+id/textview"/><EditTextAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/edtsex"Android:text=""Android:inputtype= "Text"/><TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Age"/><EditTextAndroid:id= "@+id/edtage"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:inputtype= "Number"Android:text=""/><ButtonAndroid:id= "@+id/btndosug"Android:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:text= "suggestion"/> <  TextView Android:id= "@+id/txtresult" android:layout_width= "Match_parent" android:layout_ Height= "wrap_content" android:text= "Result:"/></linearlayout> 

The important point

GetText () get the text;

Integer.pareseint () converted to int type;

ToString () is converted into a string;

SetText () set the text;

A.equals (B) the judgment is equal;

Real-time testing, according to the past should be set up USB debugging, a few years ago remember the phone or there is this option, today looking for half a day did not find, the Internet found the solution:

Find the version number on this machine, then 3, then the developer option will appear in the next 4. All right.... Thief Magic .....

Android simple application test water and real machine testing problem solving

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.