在我的应用程序中,我有一个微调器和一个ViewStub,这取决于从微调器中选择的用户项目,我必须为不同的布局充气并在微调器下方显示充气的布局。当我的应用程序启动时,ViewStub在第一次从微调器中选择任何项目时成功地扩展了布局。当我尝试从微调器中选择一个新项目时,它会在下面引发异常
java.lang.IllegalStateException: ViewStub must have a non-null ViewGroup viewParent
到目前为止我的代码是
@Override
public void onItemSelected(AdapterView<?> pParent, View pView, int pPosition, long pId) {
if(pPosition == 1){
m_cStub.setLayoutResource(R.layout.text_form);
}else if(pPosition == 2){
m_cStub.setLayoutResource(R.layout.integer_form);
}
View inflated = m_cStub.inflate();
}
m_cStub 是在 Activity 的onCreate()内部创建的ViewStub对象。
这是我的主要布局 xml 代码
<RelativeLayout..................>
<spinner......................./>
<ViewStub android:id="@+id/dynamic_form_layout"
android:inflatedId="@+id/dynamic_form_inflated_id"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
谁能告诉我哪里出错了。如果您有任何其他解决方案可以解决此问题,请分享。
谢谢。