Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add a tag or id to a Fragment
    primarykey
    data
    text
    <p>This is my pager adapter.</p> <pre><code>public static class PagerAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBar mActionBar; private final ViewPager mViewPager; private final ArrayList&lt;TabInfo&gt; mTabs = new ArrayList&lt;TabInfo&gt;(); static final class TabInfo { private final Class&lt;?&gt; clss; private final Bundle args; TabInfo(Class&lt;?&gt; _class, Bundle _args) { clss = _class; args = _args; } } public PagerAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBar = activity.getSupportActionBar(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBar.Tab tab, Class&lt;?&gt; clss, Bundle args) { TabInfo info = new TabInfo(clss, args); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBar.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment) Fragment.instantiate(mContext, info.clss.getName(), info.args); } public void onPageSelected(int position) { mActionBar.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) { } public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); Log.d("Tab position selected = ", "" + tab.getPosition()); // Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i = 0; i &lt; mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) { } public void onTabReselected(Tab tab, FragmentTransaction ft) { } } </code></pre> <p>How can i add a tag or an id to the fragments in each tab. So that i can access them later.</p> <p>Thank You</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload