Reputation: 34041
Given a PopupWindow
defined like this:
public class MyWindow extends PopupWindow implements View.OnTouchListener {
MyWindow(View view) {
super(view);
setHeight(view.getMeasuredHeight());
setFocusable(true);
setTouchable(true);
setTouchInterceptor(this);
}
public boolean onTouch(View v, MotionEvent event) {
System.out.println("onTouch()");
return true;
}
}
for some reason, onTouch()
is never called.
What am I doing wrong? How can I get the PopupWindow
to accept touch events?
Upvotes: 2
Views: 332
Reputation: 34041
As discussed in this answer to a different question, the PopupWindow
needs to have a background Drawable
explicitly set, even when it has been inflated from XML and doesn't visually need a background set.
I fixed this by adding this line:
setBackgroundDrawable(new ShapeDrawable());
to the constructor.
Upvotes: 2