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 ?
Asked
Active
Viewed 47 times
-4
-
Looks like this is home work. Have you tried anything? – chalitha geekiyanage Jul 12 '18 at 17:32
-
1Possible duplicate of [How to display Toast in Android?](https://stackoverflow.com/questions/3500197/how-to-display-toast-in-android) – chalitha geekiyanage Jul 12 '18 at 17:34
-
Read well written – c.kmd Jul 12 '18 at 17:36
2 Answers
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();
}

Asif Mohammad Mollah
- 423
- 1
- 3
- 12

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();
}

Asif Mohammad Mollah
- 423
- 1
- 3
- 12