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
Asked
Active
Viewed 1,671 times
4 Answers
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