Я хотел бы использовать AlertDialog в качестве Входа в систему или диалогового окна пароля или PIN-кода. Вот мой код -
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();
То, как кодировать тот весь входной текст, появится как '***' - звездочка
Я не могу получить свое значение PIN-кода, хотя оно показывает в звездочку. мой код ниже
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" />
Я ввел значение, но станьте пустыми!
как решить?
Отладка останавливается в этом операторе. Когда я указал выше mUserText нулевого значения, показываемого во всплывающем окне.
Представьте strPinCode в виде строки = mUserText.getText () .toString ();
Я использую Android 1.6. Это зависит от Версии?:?:
У EditText
должен быть android:password="true"
.
Проверьте эту ссылку.