gpt4 book ai didi

android - 警报对话框输入文本

转载 作者:IT老高 更新时间:2023-10-28 22:22:54 24 4
gpt4 key购买 nike

我想使用 AlertDialog 作为登录或密码或密码对话框。这是我的代码 -

    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();

如何编码所有输入文本都将显示为“***” - 星号

我无法获取我的密码值,尽管它显示为星号。我的代码在下面

    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" />

我输入了值,但得到了 null!

如何解决?

在此语句处停止调试。当我指出上面的 mUserText 空值显示在弹出窗口中时。

String strPinCode = mUserText.getText().toString();

我使用 Android 1.6。它取决于版本吗? :?:

最佳答案

这个问题可以在不使用已弃用的 android:password 的情况下解决。看我的回答here .

关于android - 警报对话框输入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3011361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com