-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewPager2TabLayout.java
45 lines (36 loc) · 1.5 KB
/
ViewPager2TabLayout.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
private class SwipeView extends RecyclerView.Adapter<SwipeView.ViewHolder> {
private LayoutInflater layoutInflater;
private Resources resources;
public SwipeView() {
layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE);
resources = getResources();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View inflate = layoutInflater.inflate(R.layout.pager, parent, false); // inflate(R.layout.pager, null);
return new ViewHolder(inflate);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.textView.setText("TEXT");
}
@Override
public int getItemCount() {
return MainActivity.this.arrayList.size();
}
private class ViewHolder extends RecyclerView.ViewHolder {
private TextView textView;
ViewHolder(View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.textView);
}
}
}
private class PageListener extends ViewPager2.OnPageChangeCallback {
@Override
public void onPageSelected(int position) {
textView.setText(MainActivity.this.arrayList.get(position).getText());
}
}
viewPager2.setAdapter(new SwipeView());
new TabLayoutMediator(tabLayout, viewPager2,true, ((tab, position) -> {})).attach();