Save a TextView value and add another

3

I'm creating a keyboard to add value to a TextView. I was able to add a value only to TextView. But what I wanted to do was to keep the current value and add another one to the side so that the user would make a number to add to TextView.

In the Onclick event I did this:

 switch (view.getId()) {
            case R.id.buttonNum1:
                txtNum.setText("1");
                break;
            case R.id.buttonNum2:
                txtNum.setText("2");
                break;

I would like to know how I can keep the current value and add a new value next.

    
asked by anonymous 18.05.2018 / 15:49

1 answer

4

Assuming that your txtNum fault object is a TextView , you can use the append method.

txtNum.append("1");

If txtNum is an object that does not have a append function, you can always do something like x = x + y, ex:

txtNum.setText(txtNum.getText() + "1");
    
18.05.2018 / 15:57