开发者

Need Help on TabActivity

I implement a TabActivity exactly like this -

http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/

Now the problem is, I have some Spinner in an activity. When i cli开发者_Go百科ck to expand the Spinner - the following exception occur -

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

Anybody have solution?


The error might be due to the context of your adapter, try giving getParent() as the context of the adapter instead of this.

this link will help you.


The problem is that using "normal" layout inflation, the context used to inflate with is "this" which is the nested Activity. Unfortunately, an Activity nested inside a tab (an ActivityGroup) can't be used to show dialogs (I'm not exactly sure why that is, but it produces the BadTokenException). The solution I found most palatable is to not use setContentView(int id) but rather do explicit inflation using getParent() as the Context. Like this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View contentView = LayoutInflater.from(getParent()).inflate(R.layout.my_layout, null);
    setContentView(contentView);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜