Android: Check if EditText is Empty when inputType is set on Number/Phone

后端 未结 9 1405
孤独总比滥情好
孤独总比滥情好 2020-12-25 15:37

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

9条回答
  •  时光取名叫无心
    2020-12-25 16:12

    You can check using the TextUtils class like

    TextUtils.isEmpty(ed_text);
    

    or you can check like this:

    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
    }
    

提交回复
热议问题