How do a simple calculator in Android? How to do it using Buttons and single edit text?

后端 未结 3 947
轮回少年
轮回少年 2021-01-26 00:52

I am learning Android so I want to keep things simple.

I have to add two numbers and display the result in a single editbox. To add with the second number you have stor

3条回答
  •  灰色年华
    2021-01-26 01:13

    Your above code was almost correct but small logic was missed in that programming . After clicking button it will store string values into "a" its ok . After that we click on operator symbol "a" will store into "aa" variable.

    example:

    a="4";
    aa=a;//aa="4"
    
    //After you do like this below way .
    
    c=Integer.parseInt(aa)+Integer.parseInt(a);
    //In the above line c (storing integer values) = 4+4;
    //a having "4" and aa="4".
    

提交回复
热议问题