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
| AlertDialog.Builder inputbox;
final EditText input = new EditText(MainActivity.this);
inputbox = new AlertDialog.Builder(MainActivity.this);
inputbox.setView(input);
//Pré-rempli le champ avec la valeur actuelle du bouton
input.setText(sourcebutton.getTextOn());
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setImeOptions(EditorInfo.IME_ACTION_DONE);
inputbox.setMessage("Saisir une caractéristique");
inputbox.setPositiveButton("OK", new DialogInterface.OnClickListener() {
//Réaction au bouton OK
public void onClick(DialogInterface dialog, int which) {
//Place la valeur saisie dans les champs de texte du bouton
sourcebutton.setTextOff(input.getText().toString());
sourcebutton.setTextOn(input.getText().toString());
sourcebutton.setText(input.getText().toString());
}
});
inputbox.setNeutralButton("Effacer", new DialogInterface.OnClickListener() {
//Réaction au bouton effacer
public void onClick(DialogInterface dialog, int which) {
//Place une valeur nulle dans les champs de texte du bouton
sourcebutton.setTextOff("");
sourcebutton.setTextOn("");
sourcebutton.setText("");
}
});
inputbox.setNegativeButton("Annuler", new DialogInterface.OnClickListener() {
//Réaction au clic annuler
public void onClick(DialogInterface dialog, int which) {
//rien
}
});
inputbox.show(); |
Partager