我有 3 个图像按钮,按下它们每个都会打开一个弹出窗口。问题是当我单击按钮 1 时,会出现一个弹出窗口,如果我不关闭该弹出窗口而是单击按钮 2,则会出现按钮 1 和按钮 2 的弹出窗口。按下新按钮时如何关闭任何打开的弹出窗口?
这是我的代码
final ImageButton rredButton=(ImageButton)findViewById(R.id.RredButton);
rredButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popupright, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
Button btnNxtScr = (Button)popupView.findViewById(R.id.nextscreen);
btnNxtScr.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
Intent myintent1 = new Intent(colorActivity.this,colorBlueActivity.class);
startActivity(myintent1);
}
});
popupWindow.showAsDropDown(rredButton, 1, -1);
}});
这是另一个按钮(使用类似的弹出方法)
final ImageButton ryellowButton=(ImageButton)findViewById(R.id.RyellowButton);
ryellowButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
createWrongPop(arg0);
}});