0

I have a TextView with text number 50. I need to get this value, decrease it by 1 (49 the result) and set the new value on my Textview.

My code so far:

TextView mynumber;

mynumber = (TextView) findViewById(R.id.mynumber);
String coinstext = mynumber.getText().toString();
                mynumber.setText(coinstext -1);

Completely failure... any idea please?

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
Irene Lorkos
  • 41
  • 1
  • 7
  • What you get from textview is a string, you need to convert it to int or numeric types before doing any arithmetic operations. Look at http://stackoverflow.com/q/2709253/1155650 – Rohit Vipin Mathews Jan 18 '17 at 00:25

1 Answers1

0
int x = Integer.parseInt(mynumber.getText().toString());
x = x - 1;
mynumber.setText(Integer.toString(x));
Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
Irene Lorkos
  • 41
  • 1
  • 7