Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return an int from EditText? (Android)

Basically, I want an EditText in Android where I can have an integer value entered into. Perhaps there is a more appropriate object than EditText for this?

like image 731
Rob S. Avatar asked Feb 04 '11 22:02

Rob S.


People also ask

How can I change text to INT in Android Studio?

The Best Answer is you have to used. String value= et. getText(). toString(); int finalValue=Integer.

How do I get text from EditText?

Now, before we start we need to know some method of EditText which we use to get or fetch the text written in an EditText that is . getText() method and the other one is . setText() method that we use to set some pre-written text or string. EditText demo; demo=(EditText)findViewById(R.

Which method is used to get the string value from an EditText?

The method used to get the data from an EditText is getText().


1 Answers

For now, use an EditText. Use android:inputType="number" to force it to be numeric. Convert the resulting string into an integer (e.g., Integer.parseInt(myEditText.getText().toString())).

In the future, you might consider a NumberPicker widget, once that becomes available (slated to be in Honeycomb).

like image 193
CommonsWare Avatar answered Sep 28 '22 21:09

CommonsWare