-4

I have button for open other app by write name of package in edittext i want if user not write any text in edittext and click button for open app get error toast like you should name of package first .. how do like this ?

c.kmd
  • 1
  • 1

2 Answers2

0

If I understand you correctly, you need to see if the user typed something into an EditText, and if they didn't, show a toast.

// Storing EditText value in package
String package = editText.getText().getString().trim();
// calculating how many character are there in string.
int checkEmpty = package.length();
if (checkEmpty == 0) {
    Toast.makeText(getActivity(), "Error", Toast.LENGTH_LONG).show();
}
letsCode
  • 2,774
  • 1
  • 13
  • 37
0

The better way to check empty in android you can write this code.

if(TextUtils.isEmpty(editText.getText().toString())){
  Toast.makeText(getApplicationContext(), "This is empty.", Toast.LENGTH_LONG).show();
}