论坛首页 移动开发技术论坛

解决ActivityGroup的sub Activity中spinner BadTokenException的问题

浏览 3932 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-12-02   最后修改:2010-12-02

在ActivityGroup的sub activity中直接使用Spinner会遇到这样的问题。 

 

 写道
08-02 17:30:57.797: ERROR/AndroidRuntime(320): Uncaught handler: thread main exiting due to uncaught exception
08-02 17:30:57.817: ERROR/AndroidRuntime(320): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44ed8338 is not valid; is your activity running?
08-02 17:30:57.817: ERROR/AndroidRuntime(320): at android.view.ViewRoot.setView(ViewRoot.java:468)
08-02 17:30:57.817: ERROR/AndroidRuntime(320): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
08-02 17:30:57.817: ERROR/AndroidRuntime(320): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

 

 

直接看代码吧

 

你需要在你的sub activity的oncreate方法这样获得content view

 

 

 

        View contentView = LayoutInflater.from(BrowseGroup.BROWSE_GROUP).inflate(R.layout.browse, null);
        pageNoSpinner = (Spinner) contentView.findViewById(R.id.pageNo);
        ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(BrowseGroup.BROWSE_GROUP, android.R.layout.simple_spinner_item);
        for(int i=1;i<=16;i++){
            adapter.add(i);
        }
        pageNoSpinner.setAdapter(adapter);
        riddlesListView = (ListView) contentView.findViewById(R.id.categories);setContentView(contentView);
 
不能直接调用setContentView(R.layout.browse);

论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics