1

I am working on an application where I need to show the recyclerView inside recyclerView. Now, recyclerView inside recyclerView is conditional based. If we have data there for the innerRecyclerView then only we need to show it else no need to show it.

Here I am facing the issue is as follows:
On the 1st position, I have taken the condition for the showing/hiding inner recyclerView, Then in the rest condition main recyclerView is loading data properly.

Now on the 0th position of recyclerView if I am showing the innerRecyclerView there them the 1st position of the main outer recyclerView will load the data for the 1st position of ArrayList, whereas it should start from the 0th position of ArrayList. So here the 0th data from the ArrayList was skipped and load the data from the 1st position of recyclerView.

Is there any way to load the 0th data from the ArrayList in the 1st position of recyclerView?

The logic for the code is like:

@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, final int position) {
    if (viewHolder instanceof HomeViewHolder) {
        if(position == 0} {
            // Data for the innerRecyclerView is available:
            if(recentList.size() > 0 ) {
                // Show innerRecyclerView..
                // Load data for the inner recyclerview.
            } else {
                // Hide the inner recyclerView..
            }
        } else {
            // Load the data for the outer recyclerView with the rest of the position..
            // If we are showing the innerRecyclerView then it will start only loading the data from the position 1 from the array list..
        }
    }
}

Please consider the design for the screen as:

enter image description here

Please let me know if you have any queries on this question.

Kishan sharma
  • 701
  • 1
  • 6
  • 20

1 Answers1

0

So since you only need to show the innerRecyclerview on 0th position. Why not just move the innerRecyclerview out of the outerRecyclerview?

When you have the innerRecylcerview stack on top of outterRecylerview. you can do this:

Lets call outterlist = mainList, and innerList = horizontalList

For example, you have a mainList that fills the outerRecyclerview. Now All you need to do is

if(!mainList.isEmpty()){
   if(MainList.get(0) == "the condition"){
 // show the horizontal recylcerview stuff.
   } else { // hide the horizontal recyclerview }
}
// continue on to setup the mainRecylerview

This will help you avoid the messy code.

CrazySports101
  • 163
  • 1
  • 3
  • Here in this case, I need to scroll my inner recyclerView with the main outer recyclerView. So is there any way to scroll my inner recyclerView with my outer recyclerView? – Kishan sharma Aug 25 '20 at 11:20
  • Im not sure what that means? perhaphs you can explain why you need to scroll inner recyclerview with the main outer one? – CrazySports101 Aug 26 '20 at 18:20