我有一个从片段调用的PopupWindow,除了我的Spinner,一切都有效.当我点击我的Spinner时它会崩溃并给出错误:
"android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌android.view.ViewRootImpl$W@421a46d8无效;您的活动是否在运行?"
我的代码调用片段中的弹出窗口:
ManagerPopUp mManagerPopUp = new ManagerPopUp(getActivity());
mManagerPopUp.showPopUpAddEvent();
Run Code Online (Sandbox Code Playgroud)
我在ManagerPopUp中的代码显示Popup:
public class ManagerPopUp {
private static final String TAG = "PopUpManager";
private Context mContext;
public ManagerPopUp(Context mContext){
this.mContext = mContext;
}
public PopupWindow showPopUpAddEvent(){
final PopupWindow popUp = new PopupWindow(mContext);
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup_add_event, null);
//Code for popup event
TextView txtRoom, txtTitle, txtEnd, txtStart;
ToggleButton tgRepeateWeekly, tgAddReminder;
Button btConfirme, btCancel;
txtTitle = (TextView)layout.findViewById(R.id.txt_lesson_title_event);
txtRoom = (TextView)layout.findViewById(R.id.txt_lesson_room_event);
txtStart = (TextView)layout.findViewById(R.id.txt_lesson_start_hour_event);
txtEnd = (TextView)layout.findViewById(R.id.txt_lesson_end_hour_event); …Run Code Online (Sandbox Code Playgroud) android android-adapter android-fragments android-spinner android-popupwindow