I am currently using ABS, ActionBar tabs and TabsAdapter / ViewPager to create a nice tab layout for my application. I have category 5+ tabs up - eventually the user will be able to add new categories (I will also install this later). So, at the moment I have the main SherlockFragmentActivity
with many files of the SherlockFragment
category. In onCreate for the main SFA, I create an actionBar and add all its tabs, for example:
mTabsAdapter.addTab(bar.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bar.newTab().setText("Geographics"), GeoFragment.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bar.newTab().setText(R.string.elections), ElectionsFragment.class, null);
Instead, I would like to create a new CategoryFragment
solution instead of using all the specific choices, Geo, Econ, etc. Can someone provide a solution? Ideally, I would just like to pass the string to the tab that is being added, so that CategoryFragment can just inflate based on the string. I would like this solution because the code is very redundant in several classes, when the whole class really works, this is the loading material from SQL dB online, receiving only data for its own category.
Here is my TabsAdapter class:
public class TabsAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private Polling activity; private final ActionBar mActionBar; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); final class TabInfo { private final Class<?> clss; private final Bundle args;
source share