I have a Settings Activity in Android Studio and a password List item that when clicked prompts an EditTextPreference
dialogue with InputType
password. How can I make it so that when the user enters the password, another Dialog pops up asking the user to confirm the password change.
Or even better, how can I make the EditTextPreference
multi line and prompt for old password, new password, confirm new password within the same Dialog?
I added the following in my main activity's onCreate
ListView lv;
Context ctx=this;
onCreate() {
lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 1) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctx);
alertDialog.setTitle("Values");
final EditText oldPass = new EditText(ctx);
final EditText newPass = new EditText(ctx);
final EditText confirmPass = new EditText(ctx);
oldPass.setTransformationMethod(PasswordTransformationMethod.getInstance());
newPass.setTransformationMethod(PasswordTransformationMethod.getInstance());
confirmPass.setTransformationMethod(PasswordTransformationMethod.getInstance());
LinearLayout ll = new LinearLayout(ctx);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(oldPass);
ll.addView(newPass);
ll.addView(confirmPass);
alertDialog.setView(ll);
alertDialog.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
alertDialog.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = alertDialog.create();
alert11.show();
}
}
});
}
But there is no change in the behavior of the app. The listItem I'm focusing on is second from the top so presumably position == 1.
I created a
LinearLayout
and added twotextBoxes
into it and then gave it to thealertBox
.Check the passwords with the object references
oldPass
andnewPass
.If you want to add anymore objects on to it, just create and add to the view.
To deal with the problem that when I cancel or pressed yes in this new dialog, the old dialog would appear, I changed "EditTextPreference" to simply "Preference" in my pref_general.xml file. Now the old dialogue does not appear or show up at all and the problem is fixed.