vla*_*ija 1 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();
}
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
1626 次 |
| 最近记录: |