AlertDialog输入文本 [英] AlertDialog Input Text
问题描述
我想用AlertDialog作为登录或销code或密码对话框。这是我的code -
I'd like to use AlertDialog as a Login or pin code or password dialog. Here is my 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();
如何code,所有输入的文字会出现像的 * 的 - 星号
我不能让我的脚code值虽然它显示为星号。我的code低于
I can't get my pin code value although it shows into asterisk. my code is below
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
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" />
我输入的值,但得到空!
I entered the value, but get null!
如何解决?
调试停止在此声明。当我指出上述mUserText空值被显示在弹出。
Debugging is stopped at this statement. When I pointed above mUserText null value being shown in popup.
字符串strPin code = mUserText.getText()的toString();
String strPinCode = mUserText.getText().toString();
我采用Android 1.6。这是否取决于版本? :?:
I use Android 1.6. Does it depend on Version? :?:
推荐答案
您的EditText
应安卓密码=真正的
。
检查这的链接。
这篇关于AlertDialog输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!