Toast mToast;
private void checkName() {
if (etName.getText().toString().isEmpty()) {
if (mToast == null) { // Initialize toast if needed
mToast = Toast.makeText(this, "", Toast.LENGTH_LONG);
}
mToast.setText("Please enter your name"); // Simply set the text of the toast
mToast.show(); // Show it, or just refresh the duration if it's already shown
} else {
submit();
}
}
Das obige Programm zeigt einen Toast nur, wenn es benötigt wird. Wenn Toasts anstehen, ignoriert es einfach den Toast. Wie funktioniert das? Was bedeutet Toast = null genau?Was bedeutet Toast = null? (Android)