|
11 | 11 | import android.view.ViewGroup;
|
12 | 12 |
|
13 | 13 | import com.zhy.autolayout.utils.AutoUtils;
|
| 14 | +import com.zhy.base.adapter.recyclerview.CommonAdapter; |
14 | 15 | import com.zhy.sample.R;
|
15 | 16 | import com.zhy.sample.view.DividerItemDecoration;
|
16 | 17 |
|
@@ -42,51 +43,33 @@ private void initView()
|
42 | 43 | mList.add(i + "");
|
43 | 44 | }
|
44 | 45 | mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
45 |
| - mRecyclerView.setAdapter(new MyAdapter()); |
| 46 | + mRecyclerView.setAdapter(new MyAdapter(getActivity(),mList)); |
46 | 47 |
|
47 | 48 | mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),
|
48 | 49 | DividerItemDecoration.VERTICAL_LIST));
|
49 | 50 | }
|
50 | 51 |
|
51 |
| - class MyAdapter extends RecyclerView.Adapter<ViewHolder> |
| 52 | + class MyAdapter extends CommonAdapter<String> |
52 | 53 | {
|
53 |
| - @Override |
54 |
| - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) |
55 |
| - { |
56 |
| - View convertView = LayoutInflater.from(mContext).inflate(R.layout.recyclerview_item, parent, false); |
57 |
| - return new ViewHolder(convertView); |
58 |
| - } |
59 |
| - |
60 |
| - @Override |
61 |
| - public void onBindViewHolder(ViewHolder holder, int position) |
| 54 | + public MyAdapter(Context context, List<String> datas) |
62 | 55 | {
|
63 |
| - |
| 56 | + super(context, R.layout.recyclerview_item, datas); |
64 | 57 | }
|
65 | 58 |
|
66 | 59 | @Override
|
67 |
| - public long getItemId(int position) |
| 60 | + public com.zhy.base.adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) |
68 | 61 | {
|
69 |
| - return position; |
| 62 | + com.zhy.base.adapter.ViewHolder viewHolder = super.onCreateViewHolder(parent, viewType); |
| 63 | + AutoUtils.autoSize(viewHolder.getConvertView()); |
| 64 | + return viewHolder; |
70 | 65 | }
|
71 | 66 |
|
72 | 67 | @Override
|
73 |
| - public int getItemCount() |
| 68 | + public void convert(com.zhy.base.adapter.ViewHolder viewHolder, String s) |
74 | 69 | {
|
75 |
| - return mList.size(); |
76 | 70 | }
|
77 |
| - |
78 |
| - |
79 | 71 | }
|
80 | 72 |
|
81 |
| - static class ViewHolder extends RecyclerView.ViewHolder |
82 |
| - { |
83 | 73 |
|
84 |
| - public ViewHolder(View itemView) |
85 |
| - { |
86 |
| - super(itemView); |
87 |
| - //对于listview,注意添加这一行,即可在item上使用高度 |
88 |
| - AutoUtils.autoSize(itemView); |
89 |
| - } |
90 |
| - } |
91 | 74 |
|
92 | 75 | }
|
0 commit comments