I've extended FragmentPagerAdapter but reading the example implementation automatically generated by Android Studio's tabbed application preset, getItem, getCount, and getPageTitle seem to have a lot of duplicated code. It uses a switch statement and hardcodes what tabs you can have and their names for the UI. This doesn't seem to be a very good solution. So I modified the solution to use a list internally to store the Fragments.When I came to modifying the getPageTitle method, I had two choices:I could either extend Fragment, add a way to method that returns the desired name, and then make all tabs extend from this extended class,or I could simply use .getClass().getSimpleName() and some string processing to get it.Of course, I would(String) getResources().getText(getResources().getIdentifier(key, string, com.example.app));after that to get localized strings from strings.xml.From what I've seen, it's popular to name classes in upper camelCase, followed by the class name it has extended.For example: if I had three tabs that were settings, history, and test results, they would be named SettingsFragment, HistoryFragment, and TestResultsFragment. As long as I consistently name it in this manner, the string processing that I did before will always work.I remember in school that it was a bad idea to use .getClass() unless you're debugging. I felt a little dirty implementing option 2 but it's significantly less code and seemingly less complex.public class SectionsPagerAdapter extends FragmentPagerAdapter {    private List<Fragment> mFragmentList;    public SectionsPagerAdapter(FragmentManager fm) {        super(fm);        mFragmentList = new ArrayList<Fragment>();    }    public void addFragment(Fragment fragment) {        mFragmentList.add(fragment);    }    @Override    public Fragment getItem(int position) {        return mFragmentList.get(position);    }    @Override    public int getCount() {        return mFragmentList.size();    }    @Override    public CharSequence getPageTitle(int position) {        //regex handles case where class name can more than one word like TestResultsFragment => test_results        String className = mFragmentList.get(position).getClass().getSimpleName();        return (String) getResources().getText(getResources().getIdentifier(className.substring(0, className.length() - 8).replaceAll(([a-z])([A-Z]+), $1_$2).toLowerCase(), string, com.example.app));        //fragment.length() == 8    }}Or is there another method that I haven't thought about?
Passing the name of a class to the UI
java;android