Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - PopupWindow not showing when using post

When I call showAsDropDown without post, (i.e., straight in code) I see the popup -

PopupWindow w = new PopupWindow(v.getContext());
w.showAsDropDown(v);

however, when I'm trying to use v.post() (either with or without delay), I do not see the popup.

v.post(new Runnable() {
            @Override
            public void run() {
                w.showAsDropDown(v);
            }
        });

What could be causing this?

like image 261
Gal Avatar asked May 08 '26 00:05

Gal


1 Answers

Well, I feel rather foolish, but I've found the problem, and am leaving the question + solution for future generations -

The problem was that I forgot to call update in the post :)

v.post(new Runnable() {
            @Override
            public void run() {
                w.showAsDropDown(v);
                w.update(v, 0, 0, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            }
        });

this code works.

like image 137
Gal Avatar answered May 09 '26 12:05

Gal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!