Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage 4 Binders #9

Closed
ersps25 opened this issue Nov 24, 2015 · 1 comment
Closed

Manage 4 Binders #9

ersps25 opened this issue Nov 24, 2015 · 1 comment

Comments

@ersps25
Copy link

ersps25 commented Nov 24, 2015

I am using EnumMapBindAdapter to display userposts list .Here I am using 4 binders ,each binder has a list of size 3 .
I have problem with getEnumFromPosition() ,According to my assumptions number of executions of
getEnumFromPosition() method should be equal to number of binders (4) . But it is not happening .I have total 4 binders and I assume getEnumFromPosition()
method should execute 4 times only (0,1,2,3) ,but executions are being excedeed . My assumption may be wrong ,If I am wrong then how can
I manage 4 binders inside getEnumFromPosition() for different positions . If I put else section then it will return a single view when position exceeds .

Here is the code of SampleEnumMapAdapter.java

public class SampleEnumMapAdapter extends EnumMapBindAdapter<SampleEnumMapAdapter.SampleViewType> {

enum SampleViewType{
    TEXT,IMAGE_AND_TEXT, AUDIO_AND_TEXT, VIDEO_AND_TEXT
}

public SampleEnumMapAdapter(){
    putBinder(SampleViewType.TEXT, new TextBinder(this));
    putBinder(SampleViewType.IMAGE_AND_TEXT, new ImageAndTextBinder(this));
    putBinder(SampleViewType.AUDIO_AND_TEXT, new AudioAndTextBinder(this));
    putBinder(SampleViewType.VIDEO_AND_TEXT, new VideoAndTextBinder(this));
}

public void setData(List<TextData> dataSetText ,List<ImageAndTextData> dataSetTextAndImage ,List<AudioAndTextData> dataSetTextAndAudio ,List<VideoAndTextData> dataSetTextAndVideo ) {
    ((TextBinder) getDataBinder(SampleViewType.TEXT)).addAll(dataSetText);
    ((ImageAndTextBinder) getDataBinder(SampleViewType.IMAGE_AND_TEXT)).addAll(dataSetTextAndImage);
    ((AudioAndTextBinder) getDataBinder(SampleViewType.AUDIO_AND_TEXT)).addAll(dataSetTextAndAudio);
    ((VideoAndTextBinder) getDataBinder(SampleViewType.VIDEO_AND_TEXT)).addAll(dataSetTextAndVideo);
}

@Override
public SampleViewType getEnumFromPosition(int position){
    if (position == 0) {
        return SampleViewType.TEXT;
    } else if (position == 1) {
        return SampleViewType.IMAGE_AND_TEXT;
    } else if(position == 2){
        return SampleViewType.AUDIO_AND_TEXT;
    }else if(position == 3){
        return SampleViewType.VIDEO_AND_TEXT;
    }
    return null;
}

@Override
public SampleViewType getEnumFromOrdinal(int ordinal) {
    return SampleViewType.values()[ordinal];
}

}

@ersps25 ersps25 changed the title Problem with having 4 Binders Manage 4 Binders Nov 24, 2015
@yqritc
Copy link
Owner

yqritc commented Nov 26, 2015

@ersps25
Position parameter of getEnumFromPosition is not the position of binder, but the position in total items of binders.
Use EnumListBindAdapter class if you want to show binder items in sequence.

EnumMapBindAdapter is used for the complex layout which need the mapping of position and view type.
So use it if you RecyclerView needs to show items like the following.
eg.
2 items in TextBinder
1 items in ImageAndTextBinder
3 items in AudioAndTextBinder
1 items in ImageAndTextBinder
1 items in TextBinder
etc...

@yqritc yqritc closed this as completed Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants