越来越怪异的文字回来EditText.toString()在Android项目的方法。为什么? [英] Getting weird text back with EditText.toString() method in Android project. Why?

查看:156
本文介绍了越来越怪异的文字回来EditText.toString()在Android项目的方法。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我出现在我的一个EditText对象的理解根本的差距。我有一个活动+布局与单个的EditText对象。当我键入​​几个字符到的EditText对象并按下回车键,我找回我的安其()监听器的文本。当我使用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()方法返回一个不同的结果,并似乎是某种uninitalize的价值?我如何获得所需的字符串目前在多行文字财产,那是什么奇怪的价值?

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?

- roschler

-- roschler

推荐答案

您正在调用的toString()在一个视图对象,这可能不具有toString()定义。

You are calling toString() on a View Object, which probably does not have a toString() defined.

我相信你想调用这样的:

I believe you want to call this:

editText.getText()。的toString()

editText.getText().toString()

这篇关于越来越怪异的文字回来EditText.toString()在Android项目的方法。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆