android - 单击微调器会出现 WindowManager$BadTokenException

标签 android android-tabhost android-tabactivity android-context

我正在使用 Tabwidget,Tab 的实现方式与 tutorial 中所示的方式相同

“MainActivity -> Activity1 -> Activity2(给定图像)”

view for the current activity

现在点击微调器给出

 android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44eb8748 is not valid; is your activity running?

我试过了Android Spinner Error : android.view.WindowManager$BadTokenException: Unable to add window已经,但这对我没有帮助

我知道上下文有问题但我不知道是什么

Hear is my Intent 启动 DetailActivity

intent = new Intent(getParent(), DetailActivity.class);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("SelectActivity", intent);

下面给出的 DetailActivity 我的代码

@Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.package_detail);
        setUpViews();

        id = getIntent().getExtras().getInt("WEBSITE_ID");

        adapter = new KeywordAdapter(getApplicationContext(), id,
                getLNApplication().getKeyworddetail());
        listTags.setAdapter(adapter);

        spinneAdapter = new SpinnerListAdapter();
        spinnerList.setAdapter(spinneAdapter);
        spinnerList.setSelection(id, true);
        spinnerList
                .setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    public void onItemSelected(AdapterView<?> parent,
                            View view, int position, long id) {

                        // txtHeader.setText(getLNApplication().getWebsiteList()
                        // .get(position).getName());
                        adapter.forceReload();
                        adapter = new KeywordAdapter(DetailActivity.this,
                                position, getLNApplication().getKeyworddetail());
                        listTags.setAdapter(adapter);
                    }

                    public void onNothingSelected(AdapterView<?> parent) {

                    }
                });

    }

SpinnerAdapter 的代码

public class SpinnerListAdapter extends BaseAdapter {

        private List<ClientDetail> siteList;

        public SpinnerListAdapter() {
            siteList = getLNApplication().getWebsiteList();
        }
        
        public void forceReload() {
            notifyDataSetChanged();
            
        }

        @Override
        public int getCount() {
            return siteList.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return siteList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView;
            
//          LayoutInflater inflater = (LayoutInflater) context
//              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
//          LayoutInflater inflater = getLayoutInflater();
    
//          LayoutInflater inflater = LayoutInflater.from(DetailActivity.this.getParent());
    
            LayoutInflater inflater = LayoutInflater.from(DetailActivity.this.getParent());
                view = inflater.inflate(R.layout.spinner_item_display, null);
                TextView websiteName = (TextView) view.findViewById(R.id.spinnerItem);
            if (siteList.get(position).getName() != null) {
                websiteName.setText(siteList.get(position).getName());
                websiteName.setTextColor(0xFF000000);
            }
            return view;
        }

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            View view = convertView;
            
//          LayoutInflater inflater = (LayoutInflater) context
//                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            
//          LayoutInflater inflater = getLayoutInflater();
            
//          LayoutInflater inflater = LayoutInflater.from(DetailActivity.this.getParent());
            
            LayoutInflater inflater = LayoutInflater.from(DetailActivity.this.getParent());
                view = inflater.inflate(R.layout.spinner_dropdown_display, null);
                TextView websiteName = (TextView) view.findViewById(R.id.spinnerDropDownItem);
            if (siteList.get(position).getName() != null) {
                websiteName.setText(siteList.get(position).getName());
                websiteName.setTextColor(0xFF000000);
            }
            return view;
        }
    }

我做错了什么吗?

请帮我...非常感谢

最佳答案

通过

YourActivty.this.getParent()

作为 ContextSpinner

有关详细信息,请参阅 herehere

关于android - 单击微调器会出现 WindowManager$BadTokenException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9126112/

相关文章:

android - 在 Android 上使用 GoogleSignInClient 静默签名时出现 ApiException

android - 对 AAssetManager_fromJava 的 undefined reference

在不同的标签上触摸 2 次时发生 Android 崩溃

android - 现在不推荐使用 TabActivity 使用 Fragments 创建选项卡

android - 应用程序在后台时 PushPlugin 出错

Android - 从选项卡内的 Activity 中切换选项卡

安卓异常 : Did you forget to call 'public void setup (LocalActivityManager activityGroup)'

Android, Intent 不起作用?

android - Android TabHost 上的徽章

android - 如何将tab host与zxing二维码扫描仪集成?