Adapter実装修正

This commit is contained in:
r-ca 2024-01-28 12:54:41 +09:00
parent 874946a38d
commit 5f0e88d804
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -7,8 +7,20 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
import java.util.ArrayList;
public class ViewerViewPagerAdapter extends FragmentStateAdapter { public class ViewerViewPagerAdapter extends FragmentStateAdapter {
// Variables
private ArrayList<Fragment> fragmentArrayList = new ArrayList<>();
private ArrayList<String> fragmentTitleList = new ArrayList<>();
// Setter
public void addFragment(Fragment fragment, String title){
fragmentArrayList.add(fragment);
fragmentTitleList.add(title);
}
public ViewerViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) { public ViewerViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) {
super(fragmentActivity); super(fragmentActivity);
} }
@ -16,11 +28,11 @@ public class ViewerViewPagerAdapter extends FragmentStateAdapter {
@NonNull @NonNull
@Override @Override
public Fragment createFragment(int position) { public Fragment createFragment(int position) {
return null; return fragmentArrayList.get(position);
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return 0; return fragmentArrayList == null ? 0 : fragmentArrayList.size();
} }
} }