Back to project page android_twitter_client.
The source code is released under:
GNU General Public License
If you think the Android project android_twitter_client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.github.snambi.twitterclient.listeners; /*w w w .ja v a2 s .c om*/ import android.os.Bundle; import android.app.ActionBar.Tab; import android.app.ActionBar.TabListener; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; public class FragmentTabListener<T extends Fragment> implements TabListener { private Fragment mFragment; private final FragmentActivity mActivity; private final String mTag; private final Class<T> mClass; private final int mfragmentContainerId; private final Bundle mfragmentArgs; // This version defaults to replacing the entire activity content area // new FragmentTabListener<SomeFragment>(this, "first", SomeFragment.class)) public FragmentTabListener(FragmentActivity activity, String tag, Class<T> clz) { this(android.R.id.content, activity, tag, clz, new Bundle()); } // This version supports specifying the container to replace with fragment content // new FragmentTabListener<SomeFragment>(R.id.flContent, this, "first", // SomeFragment.class)) public FragmentTabListener(int fragmentContainerId, FragmentActivity activity, String tag, Class<T> clz) { this(fragmentContainerId, activity, tag, clz, new Bundle()); } // This version supports specifying the container to replace with fragment // content and fragment args // new FragmentTabListener<SomeFragment>(R.id.flContent, this, "first", // SomeFragment.class, myFragmentArgs)) public FragmentTabListener(int fragmentContainerId, FragmentActivity activity, String tag, Class<T> clz, Bundle args) { mActivity = activity; mTag = tag; mClass = clz; mfragmentContainerId = fragmentContainerId; mfragmentArgs = args; } /* The following are each of the ActionBar.TabListener callbacks */ public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) { FragmentTransaction sft = mActivity.getSupportFragmentManager() .beginTransaction(); // Check if the fragment is already initialized if (mFragment == null) { // If not, instantiate and add it to the activity mFragment = Fragment.instantiate(mActivity, mClass.getName(), mfragmentArgs); sft.add(mfragmentContainerId, mFragment, mTag); } else { // If it exists, simply attach it in order to show it sft.attach(mFragment); } sft.commit(); } public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) { FragmentTransaction sft = mActivity.getSupportFragmentManager() .beginTransaction(); if (mFragment != null) { // Detach the fragment, because another one is being attached sft.detach(mFragment); } sft.commit(); } public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) { // User selected the already selected tab. Usually do nothing. } }