越来越怪异的文字回来EditText.toString()在Android项目的方法。为什么?怪异、文字、方法、项目

2023-09-08 09:07:48 作者:╭╯哥只是1)个过客ミ

我出现在我的一个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()