|
1 | 1 | package com.lsjwzh.widget.recyclerviewpager;
|
2 | 2 |
|
3 | 3 | import android.support.v7.widget.RecyclerView;
|
4 |
| -import android.util.Log; |
| 4 | +import android.support.v7.widget.ViewHolderDelegate; |
5 | 5 |
|
6 |
| -import java.lang.reflect.Field; |
7 | 6 |
|
8 | 7 | public class LoopRecyclerViewPagerAdapter<VH extends RecyclerView.ViewHolder>
|
9 | 8 | extends RecyclerViewPagerAdapter<VH> {
|
10 | 9 |
|
11 |
| - private static final String TAG = LoopRecyclerViewPager.class.getSimpleName(); |
12 |
| - |
13 |
| - private Field mPositionField; |
14 |
| - |
15 | 10 | public LoopRecyclerViewPagerAdapter(RecyclerViewPager viewPager, RecyclerView.Adapter<VH> adapter) {
|
16 | 11 | super(viewPager, adapter);
|
17 | 12 | }
|
@@ -48,21 +43,7 @@ public void onBindViewHolder(VH holder, int position) {
|
48 | 43 | super.onBindViewHolder(holder, getActualPosition(position));
|
49 | 44 | // because of getCurrentPosition may return ViewHolder‘s position,
|
50 | 45 | // so we must reset mPosition if exists.
|
51 |
| - if (mPositionField == null) { |
52 |
| - try { |
53 |
| - mPositionField = holder.getClass().getDeclaredField("mPosition"); |
54 |
| - mPositionField.setAccessible(true); |
55 |
| - } catch (NoSuchFieldException e) { |
56 |
| - Log.i(TAG, "The holder doesn't have a mPosition field."); |
57 |
| - } |
58 |
| - } |
59 |
| - if (mPositionField != null) { |
60 |
| - try { |
61 |
| - mPositionField.set(holder, position); |
62 |
| - } catch (Exception e) { |
63 |
| - Log.w(TAG, "Error while updating holder's mPosition field", e); |
64 |
| - } |
65 |
| - } |
| 46 | + ViewHolderDelegate.setPosition(holder, position); |
66 | 47 | }
|
67 | 48 |
|
68 | 49 | public int getActualPosition(int position) {
|
|
0 commit comments