Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Editext having issue with backspace key

I have an AlertDialog in which I am setting a XML as its view. In that xml layout I have an EditText. But after entering data in EditText, if I am trying to delete using backspace, the characters are not getting deleted (its like backspace is not working).

Am I missing something? I searched but did not get any proper solution except adding keylistener. I think it should work simple?

Anyone there to help me.

Here is my EditText

<EditText
        android:id="@+id/TextBox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text">
        <requestFocus />
</EditText>

Dialog ceation code:

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;
      }
    });
like image 639
Android Killer Avatar asked Jul 30 '12 06:07

Android Killer


2 Answers

Do you have any onKeyListeners set? This can be the cause of the problem.

try this:

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

(adding the return false;)

like image 125
Alex Harris Avatar answered Oct 28 '22 06:10

Alex Harris


Do you have KeyEvent.KEYCODE_BACK listener? Called to process key events. You can override this to intercept all key events before they are dispatched to the window. Be sure to call this implementation for key events that should be handled normally. when you override dispatchKeyEvent method,u must call super.dispatchKeyEvent(event) when return.

like image 1
enjoy-writing Avatar answered Oct 28 '22 07:10

enjoy-writing