Skip to content

Commit 7866014

Browse files
author
Sira Lam
committed
Updated README for v1.1.0
1 parent fe1081f commit 7866014

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

README.md

+22-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A ViewPager and a PagerAdapter that can:
99
5. Won't scroll nor loop if there is only 1 item
1010
6. Works well with notifyDataSetChanged()
1111
7. Supports page indicators
12+
8. Supports different view types
1213

1314
## Demo Effect
1415

@@ -50,7 +51,7 @@ allprojects {
5051
And then add the below to your app's build.gradle:
5152

5253
```groovy
53-
implementation 'com.asksira.android:loopingviewpager:1.0.5'
54+
implementation 'com.asksira.android:loopingviewpager:1.1.0'
5455
```
5556

5657
### Step 1: Create LoopingViewPager in XML
@@ -98,7 +99,7 @@ public class DemoInfiniteAdapter extends LoopingPagerAdapter<Integer> {
9899

99100
//This method will be triggered if the item View has not been inflated before.
100101
@Override
101-
protected View inflateView() {
102+
protected View inflateView(int viewType, int listPosition) {
102103
return LayoutInflater.from(context).inflate(R.layout.item_pager, null);
103104
}
104105

@@ -107,7 +108,7 @@ public class DemoInfiniteAdapter extends LoopingPagerAdapter<Integer> {
107108
//You can assume convertView will not be null here.
108109
//You may also consider using a ViewHolder pattern.
109110
@Override
110-
protected void bindView(View convertView, int listPosition) {
111+
protected void bindView(View convertView, int listPosition, int viewType) {
111112
convertView.findViewById(R.id.image).setBackgroundColor(context.getResources().getColor(getBackgroundColor(listPosition)));
112113
TextView description = convertView.findViewById(R.id.description);
113114
description.setText(String.valueOf(itemList.get(listPosition)));
@@ -147,6 +148,21 @@ adapter.setItemList(newItemList);
147148
viewPager.reset(); //In order to reset the current page position
148149
```
149150

151+
## How do I implement different View types?
152+
153+
Simple! Override one more method in your Adapter:
154+
155+
```java
156+
@Override
157+
protected int getItemViewType(int listPosition) {
158+
//Return your own view type, same as what you did when using RecyclerView
159+
}
160+
```
161+
162+
And then, of course, according to the `viewtype` parameter passed to you in `inflateView()` and `bindView()`, differentiate what you need to inflate or bind.
163+
164+
You may also refer to the demo app for a complete example.
165+
150166
## How do I integrate a Page Indicator?
151167

152168
I don't provide a built-in page indicator because:
@@ -240,6 +256,9 @@ if you cannot accept these minor defects, I suggest you use `onIndicatorPageChan
240256

241257
## Release notes
242258

259+
v1.1.0
260+
- Added support for view type. But therefore changed parameters needed in `inflateView()` and `bindView()`.
261+
243262
v1.0.5
244263
- Added asepct ratio attribute for `LoopingViewPager`
245264
- Rewrote the way of caching Views in `LoopingPagerAdapter`, and therefore separated inflation and data binding

0 commit comments

Comments
 (0)