use of com.google.firebase.quickstart.database.java.listfragments.MyTopPostsFragment in project quickstart-android by firebase.
the class MainFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setHasOptionsMenu(true);
// Create the adapter that will return a fragment for each section
FragmentStateAdapter mPagerAdapter = new FragmentStateAdapter(getParentFragmentManager(), getViewLifecycleOwner().getLifecycle()) {
private final Fragment[] mFragments = new Fragment[] { new RecentPostsFragment(), new MyPostsFragment(), new MyTopPostsFragment() };
@NonNull
@Override
public Fragment createFragment(int position) {
return mFragments[position];
}
@Override
public int getItemCount() {
return mFragments.length;
}
};
// Set up the ViewPager with the sections adapter.
binding.container.setAdapter(mPagerAdapter);
String[] mFragmentNames = new String[] { getString(R.string.heading_recent), getString(R.string.heading_my_posts), getString(R.string.heading_my_top_posts) };
new TabLayoutMediator(binding.tabs, binding.container, (tab, position) -> tab.setText(mFragmentNames[position])).attach();
}
Aggregations