在我的父活动中,我有一个按钮,当我单击它时,会显示带有 2 个 ImageButton 的 PopUpWindow。当此 PopUpWindow 存在时,我无法单击我的父活动按钮。这是我的代码,是否有任何问题。
public class PopUpExample extends Activity {
Button but;
LinearLayout mainLayout;
PopupWindow popUp;
boolean click = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainLayout = (LinearLayout) findViewById(R.id.main_layout);
but = (Button) findViewById(R.id.main_btn);
but.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
View popView;
if(click){
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
popUp = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false),100, 50, true);
popUp.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
popUp.update();
click = false;
popView = popUp.getContentView();
ImageButton call = (ImageButton) popView.findViewById(R.id.call_btn);
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(PopUpExample.this, "Calling...", Toast.LENGTH_SHORT).show();
}
});
ImageButton sms = (ImageButton) popView.findViewById(R.id.sms_btn);
sms.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(PopUpExample.this, "Sms...", Toast.LENGTH_SHORT).show();
}
});
}else{
popUp.dismiss();
click = true;
}
}
});
}
}