有两个View,每个都设置setOnTouchListener()
来显示一个popupWindow。当我点击viewA的popupWindowA show.when我点击viewB.I想要popupWindowA dismiss和popupWindowB显示,但是只有popupWindowA dismiss, popupWindowB没有显示。任何人都可以帮助我,非常感谢你!
答案 0 :(得分:0)
你是如何处理代码的?以下是一个可行的例子。
aButton = (Button) findViewById(R.id.button_a);
bButton = (Button) findViewById(R.id.button_b);
aButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (popupWindowB != null && popupWindowB.isShowing()) {
popupWindowB.dismiss();
}
if (popupWindowA == null) {
popupWindowA = new PopupWindow(v.getContext());
}
popupWindowA.setContentView(LayoutInflater.from(v.getContext())
.inflate(R.layout.popup_a, null));
popupWindowA.setHeight(100);
popupWindowA.setWidth(100);
popupWindowA.showAtLocation(v, Gravity.CENTER, 0, 0);
}
});
bButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (popupWindowA != null && popupWindowA.isShowing()) {
popupWindowA.dismiss();
}
if (popupWindowB == null) {
popupWindowB = new PopupWindow(v.getContext());
}
popupWindowB.setContentView(LayoutInflater.from(
v.getContext()).inflate(R.layout.popup_b, null));
popupWindowB.setHeight(150);
popupWindowB.setWidth(150);
popupWindowB.showAtLocation(v, Gravity.CENTER, 0, 0);
}
});
答案 1 :(得分:0)
尝试使用setondismisslistener作为firstpopup并在其中执行所需的操作。