0

I want to parse EditText value as integer without using String. Is it possible? Just like:

Integer s1=edt1.getText().toInt();
Integer s1=Integer.parseInt(edt1.getText();
1
  • No it is not possible you need to use toString() and then parse this to integer. Commented Aug 13, 2013 at 13:20

3 Answers 3

2

I think you have to use toString() before you can convert to an Integer. getText() returns and editable which - from what I can tell - is not a valid argument for any of the Integer conversion methods.

int woohoo = Integer.parseInt(editText.getText().toString());

You don't need to create an intermediate string if that's what you're asking. You can just pass the results of methods used to get the input to the parseInt() method.

Sign up to request clarification or add additional context in comments.

Comments

0

I guess it would be

Integer value = Integer.valueOf(edit1.getText().toString())

Comments

0

Yes, it is possible:

Integer s1 = Integer.parseInt(edt1.getText().toString().trim());

But make sure that your edittext input contains only numbers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.