FragmentではなくTargetIdを持つように変更

This commit is contained in:
r-ca 2024-01-29 01:55:06 +09:00
parent c849fdae2e
commit 9084613e38
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -13,13 +13,13 @@ import java.util.ArrayList;
public class ViewerViewPagerAdapter extends FragmentStateAdapter { public class ViewerViewPagerAdapter extends FragmentStateAdapter {
// Variables // Variables
private ArrayList<Fragment> fragmentArrayList = new ArrayList<>(); private ArrayList<String> fragmentTargetIdList = new ArrayList<>();
private ArrayList<String> fragmentTitleList = new ArrayList<>(); private ArrayList<String> fragmentTitleList = new ArrayList<>();
// Setter // Setter
public void addFragment(Fragment fragment, String title){
fragmentArrayList.add(fragment); public void setFragmentTargetIdList(ArrayList<String> fragmentTargetIdList) {
fragmentTitleList.add(title); this.fragmentTargetIdList = fragmentTargetIdList;
} }
public ViewerViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) { public ViewerViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) {
@ -29,12 +29,12 @@ public class ViewerViewPagerAdapter extends FragmentStateAdapter {
@NonNull @NonNull
@Override @Override
public Fragment createFragment(int position) { public Fragment createFragment(int position) {
return fragmentArrayList.get(position); return ViewerListFragment.newInstance(fragmentTargetIdList.get(position), fragmentTitleList.get(position));
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return fragmentArrayList == null ? 0 : fragmentArrayList.size(); return fragmentTargetIdList == null ? 0 : fragmentTargetIdList.size();
} }
@Nullable @Nullable