0

我有一个弹出窗口,用户可以在其中注册和帐户。如果用户名已经存在,我使用 setError(string); 通知用户,然后我清除 Edittext 和 reqeustFocus。但是在 reqeustFocus(); 我得到 BadTokenException:

Unable to add window -- token android.view.ViewRootImpl$W@41ea39b8 is not valid; is your activity running

我正在使用 SherlockFragment,这就是我创建 PopupWindow 的方式

         LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     View layout = inflater.inflate(R.layout.popup_register,null);
     pwCreateAccount = new PopupWindow(layout, screenWidth - 75, LayoutParams.WRAP_CONTENT, true);
     pwCreateAccount.setOutsideTouchable(true);
     pwCreateAccount.setBackgroundDrawable(new BitmapDrawable());
     pwCreateAccount.showAtLocation(layout, 17, 0, 0);

我在 PopupWindow 内的微调器遇到了同样的问题,然后我尝试打开下拉列表以选择一个我遇到相同错误的项目。但我也使用了 getActivity() 而不是 getBaseContext() 或 getApplicationContext()

4

1 回答 1

0

使用对话框解决

         myDialog = new Dialog(getActivity());
     myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
     myDialog.setContentView(R.layout.popup_register);
     myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

这样我得到了自己的视图,默认背景或标题没有边框

于 2013-09-14T18:52:11.597 回答