Spinner within Child of ActivityGroup doesn't

2019-08-05 08:02发布

I have a problem with spinner inside activity , that child of Activity group . when I clicked on spinner , that isn't expanded and "Force Close" window appears I was checked Logcat and catch "BadTokenException ", see below :

http://i227.photobucket.com/albums/dd299/lavender-90/stackflow.jpg

my XML:

<Spinner  
    android:id="@+id/aroundSP"  
    android:layout_height="wrap_content"  
    android:prompt="@string/touraround"
    android:layout_width="fill_parent"  
    android:entries="@array/Triparound"
    android:layout_marginTop="250dip" 
    android:layout_marginLeft="4dip"
    style="@style/ContentTitle">
</Spinner>

Thanks everyone!

2条回答
欢心
2楼-- · 2019-08-05 08:44

If you are using context anywhere then you have to pass getParent() context because you are in a child of activity group.

查看更多
劳资没心,怎么记你
3楼-- · 2019-08-05 08:54

this works fine.

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(
                    R.layout.marketlist, null);
            this.setContentView(viewToLoad);
查看更多
登录 后发表回答