SpaceTabLayout
SpaceTabLayout copied to clipboard
tablayout initialize error after click other fragment then back to tablayout fragment
10-31 23:09:14.749 14194-14194/com.example.alfattah.absensiproject E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.alfattah.absensiproject, PID: 14194 java.lang.IllegalArgumentException: You have 3 tabs. at eu.long1.spacetablayout.SpaceTabLayout.initialize(SpaceTabLayout.java:266)
and this my code :
public class DashboardFragment extends Fragment {
public DashboardFragment() {
// Required empty public constructor
}
SpaceTabLayout tabLayout;
List<Fragment> fragmentList = new ArrayList<>();
CheckinFragment checkinFragment = new CheckinFragment();
MapsFragment mapsFragment = new MapsFragment();
CheckOutFragment checkOutFragment = new CheckOutFragment();
ViewPager dashboardViewpager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_dashboard, container, false);
dashboardViewpager = view.findViewById(R.id.viewPagerdashboard);
tabLayout = view.findViewById(R.id.spaceTabLayout);
fragmentList.add(checkinFragment);
fragmentList.add(mapsFragment);
fragmentList.add(checkOutFragment);
tabLayout.initialize(dashboardViewpager, getActivity().getSupportFragmentManager(), fragmentList, savedInstanceState);
return view;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
tabLayout.saveState(outState);
super.onSaveInstanceState(outState);
}
@Override
public void onStart() {
super.onStart();
}
}