我对 EditText 对象的理解似乎存在根本性的差距.我有一个带有单个 EditText 对象的 Activity+Layout.在我在 EditText 对象中键入几个字符并按 Enter 键后,我在我的 onKey() 侦听器中检索文本.当我使用 toString() 方法检索文本时,我得到一个奇怪的字符串,例如:
I appear to have a fundamental gap in my understanding of an EditText object. I have an Activity+Layout with a single EditText object. After I type a few characters into the EditText object and hit the Enter key, I retrieve the text in my onKey() listener. When I use the toString() method to retrieve the text I get back a weird string like:
android.widget.EditText@43749ff0
android.widget.EditText@43749ff0
尽管 EditText.mText 属性确实显示了我在测试期间输入的字符串123".为什么 toString() 返回不同的结果以及似乎是某种取消初始化"值?如何在 mText 属性中获取当前所需的字符串,那个奇怪的值是什么?
Despite the fact the EditText.mText property does show the string I entered, "123" during my tests. Why is toString() returning a different result and what appears to be some kind of "uninitalize" value? How do I get the desired string currently in the mText property and what is that strange value?
-- 罗施勒
你在一个视图对象上调用 toString(),它可能没有定义 toString().
You are calling toString() on a View Object, which probably does not have a toString() defined.
我相信你想这样称呼:
editText.getText().toString()
editText.getText().toString()
这篇关于在 Android 项目中使用 EditText.toString() 方法获取奇怪的文本.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)