Home > Mobile >  The Android application design issues
The Android application design issues

Time:09-21

Implementing calculator probably need several control
1, EditText * 2 two
2, the textView is used for displaying the results
3, starting Button used to represent the

EditText know input number, and then through the textView shows that the calculation results, use the Button can be associated with an OnClick function
The code is as follows:
The Button Button=(Button) the findViewById (R.i which ake_photo); The editText=(editText) the findViewById (R.i d.e dit_text); EditText1=(EditText) the findViewById (R.i d.e dit_text1); Button. SetOnClickListener (new View. An OnClickListener () {public void onClick (View v) {String inputText=editText. The getText (), toString (); String inputText1=editText1. GetText (). The toString (); Int num1=Integer. The valueOf (inputText) intValue (); Int num2=Integer. The valueOf (inputText1) intValue (); Num1 + num2=; InputText=String. The valueOf (num1);//inputText=inputText + inputText1;//Toast. MakeText (MainActivity. This inputText,//Toast LENGTH_SHORT), show (); TextView TextView=(TextView) the findViewById (R.i which ext_view); TextView. SetText (inputText); }});
The author thought: the key is there is a String - & gt; Int - & gt; Transformation of String
I am novice, asked a question two free
The first question: why not start directly from the editText int then two int type additive (to) press the Button the output,
The second question: String - & gt; Int then output the results don't have to do is the final result is why then converted to digital String

CodePudding user response:

Intermediate through this variable is a good habit, convenient reuse and judgment, the second problem, should be the parameters need to string type

CodePudding user response:

reference 1st floor BDMH response:
middle through this variable is a good habit, convenient reuse and judgment, the second problem, should be the parameters need to string type
thank?? The great spirit guide
  • Related