带有两个不接受数字作为输入的编辑文本的自定义对话框

Custom Dialog with two Edit Texts not Accepting Digits as Input

我正在为我的对话框创建自定义布局以接受用户名和密码。我在下面的代码中遇到了一些奇怪的错误,当我试图在编辑文本中写入数字而不是字符串时,没有显示任何内容,就好像我没有写任何东西一样,尽管这种情况并没有在所有 android 手机上发生。这个案例是在摩托罗拉tc55上。请问有人可以帮助下面的代码吗?

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_height="wrap_content"
    android:paddingLeft="10dp" android:paddingRight="10dp"
    android:background="#10ffffff" android:layout_width="300dp"
    android:paddingTop="10dp">

    <TextView
        android:id="@+id/DialogDescription"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text=""
        android:layout_marginBottom="10dp"
        android:textColor="#ff8e8e90"
        android:textStyle="bold"/>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff5f5f5">

    <EditText android:layout_height="wrap_content"
        android:id="@+id/txtUsername"
        android:layout_width="match_parent"
        android:paddingLeft="30dp"
        >
        <requestFocus></requestFocus>
    </EditText>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxHeight="5dp"
            android:maxWidth="5dp"
            android:minHeight="5dp"
            android:minWidth="5dp"
            android:layout_gravity="left|center_vertical|center_horizontal"
            android:background="@drawable/ic_action_remove"
            android:id="@+id/DeleteTextUserName"
            android:layout_marginLeft="5dp"/>

    </FrameLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff5f5f5">

    <EditText android:layout_height="wrap_content"
        android:id="@+id/txtPassword"
        android:layout_width="match_parent"
        android:paddingLeft="30dp"
        >

    </EditText>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxHeight="5dp"
            android:maxWidth="5dp"
            android:minHeight="5dp"
            android:minWidth="5dp"
            android:layout_gravity="left|center_vertical"
            android:background="@drawable/ic_action_remove"
            android:id="@+id/DeleteTextPass"
            android:layout_marginLeft="5dp"/>

    </FrameLayout>
  <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:id="@+id/linearLayout1">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:id="@+id/btnLogin"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="10dp"
            android:text="Login"
            >
        </Button>

    </LinearLayout>
</LinearLayout>

在ACTIVITY中:

final Dialog login = new Dialog(this);

        login.setContentView(R.layout.admin_login_dialog);
  final EditText txtUsername = (EditText) login.findViewById(R.id.txtUsername);
        final EditText txtPassword = (EditText) login.findViewById(R.id.txtPassword);
final Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
   btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (txtUsername.getText().toString().trim().length() > 0 && txtPassword.getText().toString().trim().length() > 0) {
                    login.setTitle("Please Wait...");

                    login.hide();
                    pd = new ProgressDialog(MainActivity.this);
                    showPleaseWait(pd);
                    String Language=MainActivitySharedPref.GetValue(MainActivity.activityContextMP.getApplicationContext(), "Language");
                    if(Language.equals("ar")){Language="A";}else{Language="L";}
                    AdminAuthenticationChecker(login, txtUsername.getText().toString().trim(), txtPassword.getText().toString().trim(), Language);
                    //CheckAdminLoginLocally(txtPassword.getText().toString().trim(), txtUsername.getText().toString().trim(), login, pd);
                } else {
                    Toast.makeText(MainActivity.this, "Please enter Username and Password", Toast.LENGTH_LONG).show();
                }
            }
        });
        login.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog,
                                 int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    login.dismiss();
                }
                return true;
            }
        });
        login.setCanceledOnTouchOutside(true);

        login.show();

我将上面的代码更改为 AlertDialog,然后它工作正常。