单击后,Android PopupWindow按钮消失

时间:2012-06-12 08:46:41

标签: android popupwindow onclicklistener

我在Android上遇到了非常令人沮丧的问题 PopupWindow 。 我已经实现了自己的继承 PopupWindow 和实现的类 的 OnClickListener 即可。

添加自定义选择器的按钮背景后,问题就开始了。 单击按钮(开始新活动并关闭弹出窗口)后,此背景将一直消失。 只有在" 快速点击" 焦点并点击"后它才会消失。

任何想法/建议都会非常受欢迎!

public class TestPopup extends PopupWindow implements OnClickListener

protected LayoutInflater inflater;
protected Activity caller;
protected View popup;
protected View layout;

public TestPopup(Activity activity) {
    super(activity);
    popup = inflater.inflate(R.layout.popup, (ViewGroup) caller.findViewById(R.id.contentLayout));
    layout = popup.findViewById(R.id.layout);

    popup.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

    Display display = caller.getWindowManager().getDefaultDisplay();
    setHeight(display.getHeight());
    setWidth(display.getWidth());
    setFocusable(true);
    setContentView(popup);

    // fix to allow Popup to be clickable!
    setBackgroundDrawable(new BitmapDrawable());

    popup.setOnClickListener(this);
    popup.findViewById(R.id.addButton).setOnClickListener(this);
    popup.findViewById(R.id.deleteButton).setOnClickListener(this);
}

public void onClick(View v) {
    Intent intent = null;
    if (v.getId() == R.id.addButton) {
        intent = new Intent(caller, AddActivity.class);
        intent.putExtra(AddActivity.ACTION_ADD, true);
    } else if (v.getId() == R.id.deleteButton) {
        intent = new Intent(caller, AddActivity.class);
        intent.putExtra(AddActivity.ACTION_DELETE, true);
    }

    if (intent != null) {
        caller.startActivity(intent);
    }

    TestPopup.this.dismiss();
}

Popup

1 个答案:

答案 0 :(得分:4)

一种解决方案是在解除弹出窗口之前调用 popup.invalidate();

相关问题