cymcsg / UltimateRecyclerView

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
Apache License 2.0
7.22k stars 1.43k forks source link

Position in DataBinder possibly wrong? #193

Closed kientux closed 8 years ago

kientux commented 9 years ago

First, sorry for my bad English.

I was successfully implement UltimateDifferentViewTypeAdapter to support multiple view type in recycler view (I have 3 view types). But in this method:

public class MyDataBinder extends DataBinder<MyDataBinder.MyViewHolder> {
    ....

    @Override
    public void bindViewHolder(MyViewHolder holder, int position) {
        Log.d(TAG, String.valueOf(position));
        MyData data = dataList.get(position);
    }

}

position here is not the position of MyViewHolder in recycler view. If I get object from dataList with that position, the object might be wrong.

For example, I have an array: [1, a, 2, b, 3, c] with 2 view types NumberViewHolder and CharacterViewHolder.

position in DataBinder of NumberViewHolder will be 0 - 1 - 2; and it supposed to be 0 - 2 - 4. position in DataBinder of CharacterViewHolder will be 0 - 1 - 2; and it supposed to be 1 - 3 - 5.

I mean, it's like you split the array into 2 array based on which view type, then get position from each array, not from original array.

In your example app, MultiViewTypesActivity shows each data two times because of this. I don't know if this is a bug or just the code design?

hungnguyenvan commented 9 years ago

I have fixed it! @Override public void onBindViewHolder(UltimateRecyclerviewViewHolder viewHolder, int position) { // int binderPosition = getBinderPosition(position);//Remove-No no need //Hung fixed getDataBinder(viewHolder.getItemViewType()).bindViewHolder(viewHolder, position);

}
netanelgilad commented 8 years ago

+1 on this. @cymcsg if you think the fix here is correct I can PR with the fix.

cymcsg commented 8 years ago

@netanelgilad @hungnguyenvan All of you think that is correct ,aren't you? I hope the PR of the problem.

cymcsg commented 8 years ago

temp fix in https://github.com/cymcsg/UltimateRecyclerView/commit/79753c5bad0883c1763f4c1b2061a13b767ee9e0