Getting weird text back with EditText.toString() method in Android project. Why?(在 Android 项目中使用 EditText.toString() 方法获取奇怪的文本.为什么?)
问题描述
我对 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() 方法获取奇怪的文本.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Android 项目中使用 EditText.toString() 方法获取奇怪的文本.为什么?


基础教程推荐
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 从 python 访问 JVM 2022-01-01