-2

How can I check white space in edittext if edittext is white space only return null but I don't want to disable white space cause some time user use "firstname lastname" I try to check like feature change name in application Line

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Neko Mimi
  • 31
  • 5

4 Answers4

4
   EditText et_username=(EditText)findViewById(R.id.et_username);
    if(et_username.getText().toString().trim().length()==0)
    {

    }
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Komal12
  • 3,340
  • 4
  • 16
  • 25
0

You can use TextUtils class of android like this

String text = editText.getText().toString().trim();
if(!TextUtils.isEmpty(text)) {
      //Your code
}
Piyush
  • 2,589
  • 6
  • 38
  • 77
0

You can use TextWatcher:

editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.toString().trim().equals("")) {
                Log.i(TAG, "onTextChanged: empty");
            }  
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
Vaibhav Jain
  • 163
  • 13
0
EditText edtUsername=(EditText)findViewById(R.id.edtUsername);
String strEdtUsername= edtUsername.getText().toString().trim();

if(strEdtUsername.length() != 0){
    //Your code
}
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Dinithe Pieris
  • 1,822
  • 3
  • 32
  • 44