問題描述
我對 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模板網!