1

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();
}

現れる

4

1 に答える 1

6

1 つの解決策は、 popup.invalidate();を呼び出すことです。ポップアップを閉じる前に。

于 2012-06-12T11:11:33.463 に答える