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