EditText ed1 = (EditText)findViewById( R.id.editText1 );
int a = Integer.parseInt( ed1.getText().toString() );
上面的代码是否从用户那里获取数字输入并将其显示为字符串?
我的要求是将输入作为整数并作为字符串返回。我该怎么做?
最佳答案
Is the above code referencing that get the input as numeric from the user and show it as string?
反过来 - 它会经历这些步骤:
- 找到编辑框
- 从编辑框中获取文本
- 将文本解析为数字
My requirement is to get the input as integer and return as Strings
从哪里获取输入?如果您从用户 获得输入,那么它可能已经是字符串形式。如果您尝试从代码中的其他地方转换整数,那么您可以使用
String text = Integer.toString(number);
...或者您可以使用 NumberFormat
对象,它会考虑不同的文化信息,允许对数字等进行分组。
关于java - Android Java 源代码中的歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10845016/