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?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Set the digits attribute to true, which will cause it to only allow number inputs.
Then do
Integer.valueOf(editText.getText())
to get an int value out.For now, use an
EditText
. Useandroid: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).First of all get a string from an EDITTEXT and then convert this string into integer like
You can do this in 2 ways:
1: Change the input type(In your
EditText
field) in the layout file toandroid:inputType="number"
Or
2: Use
int a = Integer.parseInt(yourEditTextObject.getText().toString());