小编Ger*_*ort的帖子

"使用popupwindow避免将null作为视图根"传递

所以,我的程序运行正常.我只留下三个警告(每个弹出窗口一个),它让我很烦恼,我一直在寻找一个能满足我需求的解决方案,但我似乎无法找到一个.

这是我的代码(其他两个popupwindows相似)

else if(id == R.id.action_resetstats){
        LayoutInflater layoutInflater  = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
        View popupView = layoutInflater.inflate(R.layout.resetpop, null);
        final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        Button yesDismiss = (Button)popupView.findViewById(R.id.yesDismiss);
        yesDismiss.setOnClickListener(new Button.OnClickListener(){
            @Override
            public void onClick(View v){
                SharedPreferences prefs = getSharedPreferences(savedData, Context.MODE_PRIVATE);
                Editor editor = prefs.edit();
                editor.clear();
                editor.commit();

                counterW = 0;
                counterL = 0;
                counterT = 0;
                counterTot = 0;
                timerTime = 3;

                popupWindow.dismiss();
            }
        });    

        popupWindow.showAsDropDown(yeDismiss, 50, 50);


        Button noDismiss = (Button)popupView.findViewById(R.id.noDismiss);
        noDismiss.setOnClickListener(new Button.OnClickListener(){
            @Override
            public void onClick(View v){
                popupWindow.dismiss();
            }
        });    

        popupWindow.showAsDropDown(naDismiss, …
Run Code Online (Sandbox Code Playgroud)

null android popupwindow android-layout layout-inflater

2
推荐指数
1
解决办法
2419
查看次数