运行一个包含片段的Activity时,出现膨胀片段错误。
CheckList是一个包含listview和Description片段
的Activity,其xml代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<fragment class="com.uday.honeytest.CheckList$listview"
android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent" />
<fragment class="com.uday.honeytest.CheckList$Description"
android:id="@+id/details" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
CheckList类是:
public class CheckList extends Activity {
static int position=0;
static CheckList check;
public void onCreate(Bundle saved){
super.onCreate(saved);
setContentView(R.layout.checklist);
}
public static class listview extends ListFragment {
View mConverView;
String[] items;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
xxxxxx..
return mConverView;
}
}
同样地,我下面有一个描述片段。但是我得到了:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uday.honeytest/com.uday.honeytest.CheckList}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
在setContentView的代码行出现了错误。
我的Description片段类是:已编辑:
public static class Description extends Fragment {
View mConverView;
String details[];
public static Description getInstance() {
Description desc=new Description();
return desc;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
TextView textview=new TextView(getActivity());
textview.setLayoutParams(new LayoutParams(MarginLayoutParams.WRAP_CONTENT, MarginLayoutParams.WRAP_CONTENT));
return textview;
}
}
我在这里做错了什么??
谢谢
android.support.v4.app
而不是android.app.Fragment
,因为我在API级别8下运行(Android在Android 3.0(API级别11)中引入了片段)android:layout_marginTop="?android:attr/actionBarSize"
与API级别8不兼容-请参见https://dev59.com/WlzUa4cB1Zd3GeqP0zV2