当我在弹出窗口中单击微调器时,活动完成

时间:2018-07-13 12:21:48

标签: android

大家好,我在弹出窗口中单击微调框时,我的活动结束了。但我没有针对小米和htc的三星手机出现此错误。我无法理解为什么我只有小米和htc出现此错误。我尝试解决了它,但没有解决。我发现了诸如this之类的问题 但是它没有解决这个问题。他使用对话框屏幕ı不想使用对话框屏幕。 这是我的源代码:

public void popup_show(){
    inflater = (LayoutInflater) anaurun.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layout = inflater.inflate(R.layout.adet_popup, (ViewGroup) findViewById(R.id.adet_layout));
    adet_spin = layout.findViewById(R.id.adet_spin);

    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int height = displayMetrics.heightPixels;
    int width = displayMetrics.widthPixels;
    popWin = new PopupWindow(layout, width, height, true);
    popWin.showAtLocation(layout, Gravity.CENTER, 0, 0);
    adapter = new spinner_adapter(this, adet);
    adet_spin.setAdapter(adapter);
    adet_spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            secili_adet=Integer.valueOf(adet.get(position));
            Log.d("adet",secili_adet+"");
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
}

并且我有这样的错误:

07-13 14:51:59.195 3042-3042/com.example.hakan.menuglobal E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hakan.menuglobal, PID: 3042
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@845c492 is not valid; is your activity running?
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:696)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:347)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
    at android.widget.PopupWindow.invokePopup(PopupWindow.java:1380)
    at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:1236)
    at android.widget.ListPopupWindow.show(ListPopupWindow.java:671)
    at android.widget.Spinner$DropdownPopup.show(Spinner.java:1235)
    at android.widget.Spinner.performClick(Spinner.java:770)
    at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:442)
    at android.view.View$PerformClick.run(View.java:22295)
    at android.os.Handler.handleCallback(Handler.java:754)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6342)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)

this is my popup window

我该如何解决此问题? 对不起,我的英语不好。

0 个答案:

没有答案