Multiple layouts adapter
See original GitHub issueHi, 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:
- Created 8 years ago
- Comments:7
Top GitHub Comments
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.
@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