[ AlertDialog ] Comment la réafficher si resultat non conforme ?
bonjour,
Je souhaiterais savoir comment je peux bloquer l'utilisateur sur l'AlertDialog si les champs ne sont pas remplis ???
J'ai la fonction suivant qui me permet de créer une AlertDialog que j'appelle dans le oncreate de mon Main.java.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
private void CreateUserInfoAD() {
//On instancie notre layout en tant que View
LayoutInflater factory = LayoutInflater.from(this);
final View alertDialogView = factory.inflate(R.layout.main_alertdial, null);
//Création de l'AlertDialog
AlertDialog.Builder adb = new AlertDialog.Builder(Main.this);
//On affecte la vue personnalisé que l'on a crée à notre AlertDialog
adb.setView(alertDialogView);
//On donne un titre à l'AlertDialog
adb.setTitle("Application user information (required)");
//On modifie l'icône de l'AlertDialog pour le fun ;)
adb.setIcon(android.R.drawable.ic_dialog_alert);
//On affecte un bouton "OK" à notre AlertDialog et on lui affecte un évènement
adb.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
AlertDialViewHolder mADVH = new AlertDialViewHolder();
//Lorsque l'on cliquera sur le bouton "OK", on récupère l'EditText correspondant à notre vue personnalisée (cad à alertDialogView)
mADVH.EditUsername = (EditText)alertDialogView.findViewById(R.id.EditUsername);
mADVH.EditPassword = (EditText)alertDialogView.findViewById(R.id.EditPassword);
mADVH.EditUserTelNum = (EditText)alertDialogView.findViewById(R.id.EditUserTelNum);
if ( !mADVH.EditUsername.getText().toString().isEmpty() &&
!mADVH.EditPassword.getText().toString().isEmpty() &&
!mADVH.EditUserTelNum.getText().toString().isEmpty())
{
if (mADVH.EditPassword.getText().toString().length() > 5)
{
myUser = new User((String)mADVH.EditUsername.getText().toString(),
(String)mADVH.EditPassword.getText().toString(),
(String)mADVH.EditUserTelNum.getText().toString()
);
Long myId = db.AddUser(myUser);
if (myId > 0)
Toast.makeText(Main.this, "Add Success, you can now modify your User information in PYD Settings.", 5000).show();
else
{
Toast.makeText(Main.this, "Add Failed, contact : felix.ledref@gmail.com .", 5000).show();
}
}
else
Toast.makeText(Main.this, "Password need at least 6 letters/numbers.", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(Main.this, "You have to fill all the form.", Toast.LENGTH_LONG).show();
}
}
});
adb.show();
} |
merci, bon week end à tous :ccool: !