Spinner within Child of ActivityGroup doesn't work

折月煮酒 提交于 2019-12-11 13:42:55

问题


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!


回答1:


this works fine.

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(
                    R.layout.marketlist, null);
            this.setContentView(viewToLoad);



回答2:


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



来源:https://stackoverflow.com/questions/6049496/spinner-within-child-of-activitygroup-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!