Reputation: 9419
How do I dispatch key events from a focusable PopupWindow to an underlying Activity. If I set the window as focusable, it consumes all events. I want to be able to intercept a key, and handle the event.
Here is my dilemma: My PopupWindow contains a EditText, in order to display the keyboard ontop of the window I'm forced to set the focus on the window. The problem, due to the focus, is that I can't intercept the key event, in this case the menu button, to dismiss the window.
Upvotes: 1
Views: 2473
Reputation: 19796
You can only handle event to focused view.
You could try to use my CustomPopUp.
Here how it work: if you click on EditText, type something, then open CustomPopUp and continue typing you will type in EditText. So even when you open CustomPopUp previous view is focused.
public class CustomPopUp extends PopupWindow
{
private final View.OnTouchListener customPopUpTouchListenr = new View.OnTouchListener()
{
@Override
public boolean onTouch(final View v, final MotionEvent event)
{
return false;
}
};
public CustomPopUp(final View theView)
{
super(theView);
initView();
setTouchInterceptor(customPopUpTouchListenr);
}
private void initView()
{
setWidth(LayoutParams.WRAP_CONTENT);
setHeight(LayoutParams.WRAP_CONTENT);
setTouchable(true);
setOutsideTouchable(true);
setBackgroundDrawable(new ColorDrawable());
}
}
Upvotes: 1