I am trying to create a custom adapter with a dynamic view according to the data retrieved. Everything is set up, I can differentiate the data coming and even implemented getItemViewType
and my own getItem
to set the type accordingly.
What I had:
@Override
public PostViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
PostItemView v = (PostItemView)inflater.inflate(R.layout.post_item_view, parent, false);
PostViewHolder postViewHolder = new PostViewHolder(v);
return postViewHolder;
}
Now given that getItemViewType
is implemented and getViewTypeCount
(not sure if really needed in recyclerview) I assume it will pick up the right viewType
PostItemView: concerned XML layout part looks like this:
...
<RelativeLayout
android:id="@+id/post_wrapper"
style="@style/Match">
<include
android:id="@+id/post_item_header_view"
layout="@layout/post_item_header_view"/>
<!--OLD XML includes this part and excludes FRAMELAYOUT-->
<!--<include-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:id="@+id/post_item_image_view"-->
<!--android:layout_below="@id/post_item_header_view"-->
<!--layout="@layout/post_item_image_view"-->
<!--android:layout_alignParentRight="true"-->
<!--android:layout_alignParentEnd="true" />-->
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/post_item_image_view"
android:layout_below="@id/post_item_header_view"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"></FrameLayout>
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/post_item_text_view"
android:layout_below="@id/post_item_image_view"
layout="@layout/post_item_text_view"/>
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/post_item_action_view"
android:layout_below="@id/post_item_text_view"
layout="@layout/post_item_action_view"/>
</RelativeLayout>
...
After I inflate PostItemView
, how can I inflate a specific layout in its sub FrameLayout for each type I have as I iterate through them (I have 6)?
Is there another way to do it?