我对 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() 方法获取奇怪的文本.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!