当我尝试向我的postListFragment添加页眉和页脚视图时,我得到了膨胀错误二进制XML#11
我不确定我正确地给我的页眉和页脚充气。它的postListFragment是我的列表视图
我还有一个refreshableListView类,我应该在那里膨胀标题视图吗?任何帮助表示赞赏
public PostListFragment() {
//default url
this.rssURL = GlobalClass.RSSURL;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_postlist, container, false);
View lheader = inflater.inflate(R.layout.header, null);
View lfooter = inflater.inflate(R.layout.footer, null);
postListView.addHeaderView(lheader);
postListView.addFooterView(lfooter);
postListView = (RefreshableGridView)
rootView.findViewById(R.id.postListView);
postAdapter = new PostItemAdapter(this.getActivity(), R.layout.postitem,
PostDataModel.getInstance().listData);
postListView.setAdapter(postAdapter);
postListView.setOnRefresh(this);
postListView.setOnItemClickListener(onItemClickListener);
PostDataModel.getInstance().setDelegate(this);
return rootView;
清单:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" >
<activity
android:name="com.dgcom.rssreader.SplashActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/postlistlabel" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
这是我的标题
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="#cf9f99"/>
</LinearLayout>
这是我的postlistview
<!-- activity_postlist.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#000000">
<LinearLayout android:id="@+id/adsContainer"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/postListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="300dp"
android:gravity="center"
android:horizontalSpacing="40dp"
android:verticalSpacing="200dp"
android:numColumns="2"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay"
android:stretchMode="columnWidth"
/>
</LinearLayout>
fragment_postlist
<LinearLayout android:id="@+id/adsContainer"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<com.dgcom.rssreader.component.RefreshableGridView
android:id="@+id/postListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="100dp"
android:background="@android:color/white"
android:divider="#b0b0b0"
android:choiceMode="singleChoice"
android:fadingEdge="none"
android:numColumns="2"
android:scrollbarStyle="outsideOverlay" />
</LinearLayout>
页脚布局
答案 0 :(得分:0)
你只需要移动postListView =(RefreshableGridView)rootView.findViewById(R.id.postListView);在查看rootView = ...行之后右转。我之前没有注意到你刚刚在错误的地方进行了初始化。 - Mike M. 19小时前