0
私は、RecyclerViewではなく水平であるfill_parent幅の断片を持つ垂直RecycleListを実装しようとしています。 断片化したRecycleView
私はこのエラーを取得してい: 1)それは、リスト内のリストを実装するための良い方法です:
android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
ザッツが問題でしょうか? 2)なぜこの例外が発生するのですか?
コード:あなたのRecyclerViewのアダプタで
VerticalList (fragment_recommendation_layout.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAppBg"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/cardList"
tools:listitem="@layout/fragment_recommendation_vertical_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Vertical list item (fragment_recommendation_vertical_list.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:orientation="vertical">
<TextView
android:id="@+id/rowTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:textSize="20dp"
android:text="Row Title" />
<fragment
android:id="@+id/horizontal_fragment"
android:layout_width="match_parent"
android:name="br.com.leanworks.fiquepordentro.view.recommendations.RecommendationHorizontalFragment"
android:layout_height="259dp" />
</LinearLayout>
Vertical adapter(RecommendationVerticalListViewAdapter.java)
@Override
public RecommendationItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View itemView;
RecommendationItemViewHolder recommendationItemViewHolder;
itemView = LayoutInflater.
from(viewGroup.getContext()).
inflate(R.layout.fragment_recommendation_vertical_list, viewGroup, false);
recommendationItemViewHolder = new RecommendationItemViewHolder(itemView);
return recommendationItemViewHolder;
}
Exception:
10-18 06:08:12.936 12006-12006/br.com.leanworks.fiquepordentro E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.leanworks.fiquepordentro, PID: 12006
android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at br.com.leanworks.fiquepordentro.view.recommendations.RecommendationVerticalListViewAdapter.onCreateViewHolder(RecommendationVerticalListViewAdapter.java:78)
at br.com.leanworks.fiquepordentro.view.recommendations.RecommendationVerticalListViewAdapter.onCreateViewHolder(RecommendationVerticalListViewAdapter.java:25)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5833)
ほとんどの場合、このコードで置き換えられるフラグメントは1つだけです。また、.replace()は、フラグメントではなくIDを要求します。 GetItemViewTypeとスイッチでオーバーライドを使用しませんでした。そこに問題はありますか?あなたの時間をありがとう! –
いいえ。リサイクラービューには1つのタイプの行しか含まれていない場合、戻りタイプを切り替える必要はありません。申し訳ありませんが、私の悪い:holder.getFrameLayout()。getId()は仕事をする必要があります。 – elmontoya7
お返事ありがとうございます。不幸にもそれはまだ動作しません。 :((FragmentActivity)mContext).getSupportFragmentManager()。beginTransaction()。replace(rssItemViewHolder.frameLayout.getId()、新しいRecommendationHorizontalFragment()、 "TAG")。commitAllowingStateLoss();間違った電話?私は1つのフラグメントだけが置き換えられるようになっています。 –