AlertDialog Texte d'entrée
-
26-09-2019 - |
Question
Je voudrais utiliser AlertDialog comme login ou code PIN ou mot de passe de dialogue. Voici mon code -
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Login");
alert.setMessage("Enter Pin :");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
Log.d( TAG, "Pin Value : " + value);
return;
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
return;
}
});
alert.show();
Comment code tout le texte d'entrée apparaît comme « *** » - astérisque
Je ne peux pas obtenir ma valeur de code PIN bien qu'il montre en astérisque. mon code est ci-dessous
private void accessPinCode_2()
{
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.dialog_login, null);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Login");
alert.setMessage("Enter Pin :");
alert.setView(textEntryView);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//String value = input.getText().toString();
EditText mUserText;
mUserText = (EditText) textEntryView.findViewById(R.id.txt_password);
String strPinCode = mUserText.getText().toString();
Log.d( TAG, "Pin Value : " + strPinCode);
return;
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
return;
}
});
alert.show(); }}
dialog_login.xml
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txt_password"
android:password="true"
android:layout_height="wrap_content"
android:layout_width="250px"
android:layout_centerHorizontal="true"
android:layout_below="@+id/password_text"
android:singleLine="true" />
Je suis entré dans la valeur, mais get null!
comment résoudre?
Debugging est arrêté à cette déclaration. Lorsque je l'ai souligné plus haut la valeur mUserText nulle étant représentée en pop-up.
Chaîne strPinCode = mUserText.getText () toString ();.
J'utilise Android 1.6. Est-ce que cela dépend de la version? ::
La solution
Vous EditText
devrait avoir android:password="true"
.
Vérifier ce lien .
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow