question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple layouts adapter

See original GitHub issue

Hi, First of all thanks for your work! I am happy to use your library, as it contains all the components I need to add in my app.

But currently I am facing some difficulties with adding some custom functionality. Idea is that my app has UI similar to Instagram, where there are sticky headers, then main layout (with Image, description and some other elements) and then goes section with comments, which may contain 0…n comments there. In case if I base my implementation on UltimateDifferentViewTypeAdapter there comes mess in content, as it is not shown in appropriate order. Comments are shown unrelated to content content is messed around.


Here are some implementation details to help understand app needs:

I am building logics of different layouts based on custom class IndexPath {int: section; int: row} which is based on my dataset and allows to generate plain dataset based on data I am getting from server. e.g. for data like:

Image 1: 2 comments;
Image 2: 0 comments: 
Image 3: 3 comments;

I am creating my IndexPath mapping to positions which will be like:

| Position | Section | Row | Comment   |
|----------|---------|-----|-----------|
| 0        | 0       | 0   | Img1      |
| 1        | 0       | 1   | Img1 Com1 |
| 2        | 0       | 2   | Img1 Com2 |
| 3        | 1       | 0   | Img2      |
| 4        | 2       | 0   | Img3      |
| 5        | 2       | 1   | Img3 Com1 |
| 6        | 2       | 2   | Img3 Com2 |
| 7        | 2       | 3   | Img3 Com3 |

I am having also Enum I am using like this:

public enum ViewType {
        IMAGE,
        COMMENT;

        public static ViewType forIndexPath(IndexPath indexPath) {
            if (indexPath.row == 0) { // first row is always the Image
                return IMAGE;
            } else {
                return COMMENT; // The rest are the comments
            }
        }
    }

Then for each Img I have ImgDataBinder with custom layout, as well as for each comment I have CommentDataBinder with separate layout. I am adding 2 binders to my UltimateDifferentViewTypeAdapter subclass.

I am expecting then that ImgDataBinder is used only for ViewType.IMAGE view type, while CommentDataBinder is used for ViewType.COMMENT.

But here come some troubles, as this works not as I expect it. If you have any ideas how to avoid mess with this, I would be happy to get better understanding.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Studentessacommented, Oct 10, 2016

Hello @sergii-frost , thanks you for your answer but i don’t really know what to do. Did you use UltimateDifferentViewTypeAdapter?

Ok, then, you’re not using the headers by default? I already tried that as well but it’s not sticky headers. An is heavier to use it that way, because then if I had one array of 10 elements I should have and array of 15 (for example), do you know what i mean? sorry because of my explanation is not very clear.

0reactions
sergii-frostcommented, Oct 4, 2016

@Studentessa have you tried approach I am describing in this comment?

I am managing positions in a custom way to provide different view holders base don them. Let me know if you need more help and/or explanation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper Way of using Multiple Layout Binding in Recyclerview ...
I use import androidx.recyclerview.widget.ListAdapter instead of RecyclerView.Adapter because it has many advantages over it.
Read more >
Adapter Delegate (Favor Composition Over Inheritance in ...
Creating multiple item layouts in the list can make our RecyclerView adapter complex and hard to read, even difficult to maintain. Here, Adapter...
Read more >
Android RecyclerView with multiple different layouts
The RecyclerView Item adapter, this is where the magic happens for having multiple different layouts in the RecyclerView list item.
Read more >
Heterogeneous Layouts inside RecyclerView
The following example will be inflating two different layouts for based on the object that ... public class ComplexRecyclerViewAdapter extends RecyclerView.
Read more >
Android RecyclerView Example - Multiple ViewTypes
Each of these requires a different layout type inside the RecyclerView. ... adapter class. android recycler view multiple view type project ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found