I have made an SMS app (I'm a newbie). When the user press a button a message will be sent to a number where the user types in. That goes okay! but when there there is no number (Textview is empty) the app crashes. So i tried adding a condition to when the Textview is empty send a Toast, if it is not empty send message, here my code. I tried diffrent ways but the body in Else is activated anyway? Hope someone can help me :).
sendSMSa2 is my button. nyanumtxt is where the number is.
sendSMSa2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(nyanumtxt.getText().toString().isEmpty()) {
Toast.makeText(getActivity(), "No Number chossen",
Toast.LENGTH_LONG).show();
} else {
String myMsgrela1 = a2txt.getText().toString();
String theNumberr = nyanumtxt.getText().toString();
sendMsg(theNumberr, myMsgrela1);
Toast.makeText(getActivity(), "Message sent!",
Toast.LENGTH_LONG).show();
}
}
}
);
Aucun commentaire:
Enregistrer un commentaire