单击BadTokenException时出现Android微调器异常
单击微调器(在弹出窗口中)时出现问题 这是我的弹出窗口:单击BadTokenException时出现Android微调器异常,android,spinner,popupwindow,Android,Spinner,Popupwindow,单击微调器(在弹出窗口中)时出现问题 这是我的弹出窗口: public class PopupDialog extends PopupWindow { public PopupDialog() { super(); init(); } public PopupDialog(View contentView, int width, int height) { super(contentView, width, heigh
public class PopupDialog extends PopupWindow {
public PopupDialog() {
super();
init();
}
public PopupDialog(View contentView, int width, int height) {
super(contentView, width, height);
init();
}
public PopupDialog(View contentView) {
super(contentView);
init();
}
private void init() {
this.setTouchable(true);
this.setFocusable(true);
this.setOutsideTouchable(true);
setBackgroundDrawable(new BitmapDrawable());
this.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
PopupDialog.this.dismiss();
return true;
}
return false;
}
});
}
}
单击显示弹出窗口的按钮:
public void click(View v) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupDialog popupWindow = new PopupDialog(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
popupWindow.setHeight(metrics.heightPixels);
popupWindow.setWidth(300);
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, v.getLeft()+v.getWidth(), 0);
}
我有这个例外(BadTokenException)
欢迎任何帮助,提前谢谢:)在这里进行测试
暂时删除这部分代码
this.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
PopupDialog.this.dismiss();
return true;
}
return false;
}
});
检查一下 存在上下文冲突。尝试在您的XML微调器声明中添加以下内容:
android:spinnerMode=“dialog”
我希望不会太晚。
我也有同样的问题。事情进展顺利
android:spinnerMode="dialog"
然而,我无法使用PopupWindow实现下拉(没有对话框弹出)。
通过使用alertbuilder,我得到了同样的效果
您可以按照本教程进行操作:
更改
LayoutInflater LayoutInflater=(LayoutInflater)getBaseContext()后是否尝试过。getSystemService(布局\充气器\服务)代码>到LayoutInflater LayoutInflater=(LayoutInflater)v.getContext().getSystemService(布局充气机服务)代码>?当我更改为LayoutInflater LayoutInflater=(LayoutInflater)v.getContext().getSystemService(布局\充气器\服务)时,出现了相同的问题;是的,谢谢,它在对话模式下工作得很好,但我必须在下拉模式下进行,你知道要在下拉模式下实现这一点需要做些什么吗?在我看来这是不可能的,因为弹出窗口接管了你活动的焦点。我不知道,但根据尝试次数和实现它所花费的时间,我相信你说不可能的话是对的:D非常感谢。
android:spinnerMode="dialog"