本文介紹了Android:在 Number/Phone 上設置 inputType 時檢查 EditText 是否為空的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我在 android 中有一個 EditText 供用戶輸入他們的年齡.它設置了一個 inputType=phone.我想知道是否有辦法檢查此 EditText 是否為空.
I have an EditText in android for users to input their AGE. It is set an inputType=phone. I would like to know if there is a way to check if this EditText is null.
我已經看過這個問題:檢查EditText是否為空.但它沒有解決 inputType=phone 的情況.
I've already looked at this question: Check if EditText is empty. but it does not address the case where inputType=phone.
這些,我已經檢查過了,但不起作用:
These, I've checked already and do not work:
(EditText) findViewByID(R.id.age)).getText().toString() == null
(EditText) findViewByID(R.id.age)).getText().toString() == ""
(EditText) findViewByID(R.id.age)).getText().toString().matches("")
(EditText) findViewByID(R.id.age)).getText().toString().equals("")
(EditText) findViewByID(R.id.age)).getText().toString().equals(null)
(EditText) findViewByID(R.id.age)).getText().toString().trim().length() == 0
(EditText) findViewByID(R.id.age)).getText().toString().trim().equals("")
and isEmpty do not check for blank space.
感謝您的幫助.
推薦答案
可以使用 TextUtils 類進行檢查
You can check using the TextUtils class like
TextUtils.isEmpty(ed_text);
或者你可以這樣檢查:
EditText ed = (EditText) findViewById(R.id.age);
String ed_text = ed.getText().toString().trim();
if(ed_text.isEmpty() || ed_text.length() == 0 || ed_text.equals("") || ed_text == null)
{
//EditText is empty
}
else
{
//EditText is not empty
}
這篇關于Android:在 Number/Phone 上設置 inputType 時檢查 EditText 是否為空的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!