So basically RecyclerView inflates item View wrapped in (Layout Holder). E.g.
For a RecyclerView the items that are inflated in the adapter are like :
list_item.xml contains below code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:id="@+id/option"
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="TESTING"/>
</LinearLayout>
Can it not be like below code?
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="@+id/option"
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="TESTING"/>
</merge>
Because RecyclerView is Container View that can hold simple non-container views and container views (like LinearLayout etc.)
Container Views - View which can hold simple views (TextView, button etc.) as well as container Views (like LinearLayout etc.).
Simple Views - can not hold any other view within it.
And during inflation in the adapter, we attach it root:-
final View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.dialog_locker_open_item, parent, true);
The above give exception.
It should have merged but was getting expectation during inflation.
Each
ViewHolderneeds to contain one root view (constructor argument ofViewHolder) soRecyclerViewcan detach and recycle it when needed.It's not designed to keep track of "multiple non-container views" per item (which would happen if you were inflating with
<merge>tag).Also
inflatewithattachToParent=trueis conceptually wrong and will always fail asRecyclerView.Adapteris not the component responsible for laying out the views inRecyclerView(this is the duty ofRecyclerView.LayoutManager).