I have 2 RecyclerView (Vertical) one inside the other. Outer RecyclerView is having a List of Child and within this Inner, RecyclerView is having list of devices available to the specific child. The inner RecyclerView is having a condition that it should show 2 items for the first time and these are having a button on this button click the entire list of inner RecyclerView will be visible for the particular position(child). I have easily implemented the above scenario but facing 2 problems:
- In Outer Recyclerview item click - only the last position item is expanding, on clicking to other position the item remain collapsed.
- After scrolling expanded view automatically collapsed itself.
Below I am sharing my code :
Sending complete Child list to Outer Adapter.
adapterHomeChildList.setList(responseChildList); // send list to the adapter.
2.Set list function and BindViewHolder of Outer Adapter
public void setList(List<UserWithDeviceListResponse> mChildLists) {
childLists = new ArrayList<>();
childLists = mChildLists;
notifyDataSetChanged();
}
onBindViewHolder(....)
AdapterHomeDeviceList adapterHomeDeviceList = new AdapterHomeDeviceList(context);
adapterHomeChildListBinding.setAdapter(adapterHomeDeviceList); // set inner device list adapter
if (childLists.get(position).getDeviceList() != null && !childLists.get(position).getDeviceList().isEmpty()) {
if (childLists.get(position).isExpanded()) {
adapterHomeChildListBinding.setIsSeeMore(false); // set see more button visibility
adapterHomeDeviceList.setList(childLists.get(position).getDeviceList());
} else {
if (childLists.get(position).getDeviceList().size() > 2) {
adapterHomeChildListBinding.setIsSeeMore(true);
filter(childLists.get(position).getDeviceList(), adapterHomeDeviceList); // show top 2 item only
} else {
adapterHomeDeviceList.setList(childLists.get(position).getDeviceList());
}
}
}
Item click interface handle
private void setRecyclerViewExpanding(int position) { for (int i = 0; i < responseChildList.size(); i++) { if (position == i) { if (responseChildList.get(i).isExpanded()) { responseChildList.get(i).setExpanded(false); } else { responseChildList.get(i).setExpanded(true); } } else { responseChildList.get(i).setExpanded(false); } } adapterHomeChildList.notifyDataSetChanged(); }
I have searched so many questions related to this but mostly answers are using expandable listview but I am not using an expandable view. Please do help me. Any help will be really grateful.