0

I have a a EditText field which allows only decimal numbers. How can I set it's value in the code when I press a button?

MikkoP
  • 4,864
  • 16
  • 58
  • 106

2 Answers2

2
yourEdit.setText(String.valueOf(12));
Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

You have quite a few ways to set the proper value in your EditText. Assuming you have it's @id being my_edittext:

final Integer value = 10;
final EditText myEditText = (EditText)findViewById(R.id.my_edittext);
myEditText.setText(value.toString());
myEditText.setText(Integer.toString(value));
myEditText.setText(String.valueOf(value));
// and an ugly one: 
myEditText.setText(value + "");
rekaszeru
  • 19,130
  • 7
  • 59
  • 73