sdk - Android app: Android Studio - formula calculator -


i want make simple android app min.-version 2 local use. problem have never made android apps. i've installed android studio , sdk tools now, errors when creating blank app project. vb.net programmer, know c#, php, i've never done smartphones before.

what need, simple calculator 2 text-boxes (e.g. txt1 (a) , txt2 (b) inputs doubles), calculate button, , result-field (as double).. see example-picture below.

enter image description here

when focusing text-box numeric keyboard must appear (like calc), decimal point button. , when click on result-button output must calculated , printed following formula below:

enter image description here

can give me tip how make this? or can tell write code make app work?

thank you.

so first need learn how android layout xml files work. add 4 items: 2 edittexts @ beginning, 1 button text "calculate" , finaly 1 more edittext. set of them ids (i.e. text1, text2, button, output).
don't forget set items have "match_parent" @ "layout_width" , "wrap_content" @ "layout_height" (for displaying want).

then in main activity class, in on oncreate(bundle savedinstancestate):

final edittext text1 = (edittext) findviewbyid(r.id.text1); final edittext text2 = (edittext) findviewbyid(r.id.text2); final edittext output = (edittext) findviewbyid(r.id.output); text1.setinputtype(inputtype.type_class_number | inputtype.type_number_flag_decimal); text2.setinputtype(inputtype.type_class_number | inputtype.type_number_flag_decimal); output.seteditable(false); button calculate = (button) findviewbyid(r.id.button); calculate.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view v) {         if (text1.gettext().isempty() || text2.gettext().isempty()) return;         double text1value = double.valueof(text1.gettext().tostring());         double text2value = double.valueof(text2.gettext().tostring());         double a, b;         if (text1value > text2value) {             = text1value;             b = text2value;         } else {             = text2value;             b = text1value;         }         double result = (a*a - b*b) / 4;         result = math.sqrt(result);         output.settext(string.valueof(result));     } }); 

hope helped, announce me if there errors!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -