本文介紹了獲取 EditText 的字符數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試獲取 EditText 的字符數.我研究了 EditText 和 TextView 類的不同屬性,但似乎沒有返回字符數量的函數.我曾嘗試使用 TextWatcher,但這并不理想,因為有時我會從首選項中將保存的消息加載到 EditText 中,而 TextWatcher 不會計算當時未鍵入的字符.
I'm trying to get a character count of an EditText. I've looked into different properties of the EditText and TextView classes, but there doesn't seem to be a function that returns the amount of characters. I have tried to use the TextWatcher, but that is not ideal since sometimes I load a saved message into the EditText from the preferences, and TextWatcher does not count characters not typed right then.
任何幫助都會很棒!
干杯!
推薦答案
只需將 EditText 中的文本抓取為字符串并檢查其長度即可:
Just grab the text in the EditText as a string and check its length:
int length = editText.getText().length();
這篇關于獲取 EditText 的字符數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!