How to keep adding more text in EditText field without overwriting?

  • Replies:1
Vineeth Kumar
  • Forum posts: 1

May 10, 2017, 7:41:19 AM via Website

I am new to android development and I am making a simple calculator. I have a editText field and the basic UI of a normal calculator. When I click the button "1" and then click button to display "+", the "1" displayed in the editText field is overwritten by "+". I want to keep adding text, for example, "1+2/3".

Reply
Dev Lt
  • Forum posts: 54

May 13, 2017, 7:11:38 PM via Website

In Java code you have to keep String reference of your edit text's value and everytime you press the button, you append that button value to the String value.
Pseudo code:
String value = editText.geText().toString();

// image that you click "+" button
value = value.append("+");
editText.setText(value);

Reply