我正在嘗試創建一個對話框,其中包含2個用於創建密碼的edittexts。這裏是我的代碼:比較2 EditText條目並在Android中的對話框上顯示錯誤
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setCancelable(false);
alert.setTitle(title);
alert.setMessage(message);
LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) layoutInflater.inflate(R.layout.create_pass, null);
final EditText password = (EditText) layout.findViewById(R.id.password);
final EditText passconfirm = (EditText) layout.findViewById(R.id.repeat_password);
password.setMinEms(6);
alert.setView(layout);
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (!password.getText().toString().equals(passconfirm.getText().toString())) {
passconfirm.setError(getString(R.string.password_mismatch));
return;
} else if (password.getText().toString().isEmpty()) {
password.setError(getString(R.string.password_empty));
return;
} else {
secprefs.putString("master_password", password.getText().toString());
}
}
});
alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
});
alert.show();
對話框工作正常,並且如果遵守2條件,密碼被存儲。 現在,如果不滿足2個條件,則對話框關閉。 我想撤消對話框關閉並顯示小彈出錯誤。有人知道爲什麼
我想設置的另一件事是密碼的最小長度。我嘗試setMinEms(6),但它不工作。
由於
只是一個查詢,你在哪裏創建一個對話框從建設者?你可以嘗試'alert.create()。show();'?對於第二個問題,嘗試設置'android:minEms =「'只設置它的寬度,它與最小字符數無關,以編程方式檢查 –
對話框將在onCreate方法中創建。顯示但不工作:S。 – iGio90