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;
}
});
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;)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With