Android Editext有退格键问题

And*_*ler 4 android backspace android-edittext

我有一个AlertDialog我正在设置XML它的视图.在那xml layout我有一个EditText.但是在输入数据之后EditText,如果我尝试使用退格键删除,则字符不会被删除(它就像退格键不起作用).

我错过了什么吗?我搜索但没有得到任何适当的解决方案,除了添加keylistener.我认为它应该简单吗?

有人帮助我.

这是我的 EditText

<EditText
        android:id="@+id/TextBox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text">
        <requestFocus />
</EditText>
Run Code Online (Sandbox Code Playgroud)

对话框代码:

hintDialog = new AlertDialog.Builder(activity)
    .setTitle("Enter Your Hint:")
    .setView(hintDialogView).create();
    hintDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
      @Override
      public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK)
        hintDialog.dismiss();
        return true;
      }
    });
Run Code Online (Sandbox Code Playgroud)

Ale*_*ris 10

你有任何onKeyListeners设置?这可能是问题的原因.

试试这个:

 hintDialog = new AlertDialog.Builder(activity)
.setTitle("Enter Your Hint:")
.setView(hintDialogView).create();
hintDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
  @Override
  public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK)
    hintDialog.dismiss();
    return true;
  }
  return false;
});
Run Code Online (Sandbox Code Playgroud)

(添加返回false;)