I am making a Simple Calculator, I have added 0-9 Buttons ans well as Operations such as +, -, /, * etc…
I added a Button and set its onClick event as android:onClick=”Press_1″
and its Corresponding OnClick Method is
public void Press_1(View view)
{
EditText editText=(EditText) findViewById(R.id.display);
editText.setText("1");
}
Now i want to create similarly for Button_2,Button_3 and so on… !
On pressing the buttons i want the Corresponding digits to get displayed on the editText.
Everything works fine, but i am not able to Append/Modify the EditText. Example: I want to write the number “6754”,
so i need to press ‘6’ ‘7’ ‘5’ and ‘4’ respectively , but after i press ‘7’, the ‘6’ disappears, and finally i get only ‘4’ in the EditText. Please help me i am new to this ???
Thanks !!
Instead of editText.setText(), you want to use editText.append()
http://developer.android.com/reference/android/widget/TextView.html#append%28java.lang.CharSequence%29