Denis S.
Denis S.

Reputation: 138

popup window crash if show soft keyboard

I have popup with buttons and edit text. Then I touch edit text or use

InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);keyboard

app crashed.

Error is: java.lang.IllegalArgumentException: Window type can not be changed after the window is added.

Code:

LayoutInflater layoutInflater = (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_over_map, null);
                            Context context = this.getActivity().getApplicationContext();
                            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                            DisplayMetrics metrics = new DisplayMetrics();
                            wm.getDefaultDisplay().getMetrics(metrics);
                            int displayWidth = metrics.widthPixels;
                            int displayHeight = metrics.heightPixels;
                            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(displayWidth - 10, displayHeight - 125);
                            layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
                            final PopupWindow popupWindow = new PopupWindow(popupView,
        layoutParams.width, layoutParams.height, true);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.
        SOFT_INPUT_STATE_VISIBLE);

                            Button btnDismiss = (Button) popupView.findViewById(R.id.close_window_btn);
                            btnDismiss.setOnClickListener(this);

                            etTimeUntil = (EditText)popupView.findViewById(R.id.time_et);

                            checkOnDemand = (CheckBox) popupView.findViewById(R.id.check_ondemand_popup);
            ....

Upvotes: 1

Views: 275

Answers (1)

Arsal Imam
Arsal Imam

Reputation: 2982

Please check your manifest, the targetted version should be less than 14 or remove targetted version tag....!

<uses-sdk
    android:targetSdkVersion="11"/>

I also encountered in this problem this is what which worked for me Good luck...!

Upvotes: 2

Related Questions