-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewPagerAdapter.java
More file actions
41 lines (31 loc) · 1.01 KB
/
ViewPagerAdapter.java
File metadata and controls
41 lines (31 loc) · 1.01 KB
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
package com.example.weatherapp.Adapter;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> fragmentList = new ArrayList<>();
private final List<String> fragmentTitle = new ArrayList<>();
public ViewPagerAdapter (FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem (int i) {
return fragmentList.get(i);
}
@Override
public int getCount () {
return fragmentList.size();
}
public void addFragment (Fragment fragment, String title) {
fragmentList.add(fragment);
fragmentTitle.add(title);
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return fragmentTitle.get(position);
}
}