diff --git a/src/de/podfetcher/activity/PodfetcherActivity.java b/src/de/podfetcher/activity/PodfetcherActivity.java index b1c69377a..b5d15798f 100644 --- a/src/de/podfetcher/activity/PodfetcherActivity.java +++ b/src/de/podfetcher/activity/PodfetcherActivity.java @@ -15,8 +15,12 @@ import android.widget.ListView; import android.widget.ArrayAdapter; import android.os.Bundle; import android.content.Intent; +import android.app.Activity; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockListFragment; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.ActionBar.Tab; +import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; @@ -31,14 +35,57 @@ public class PodfetcherActivity extends SherlockFragmentActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); + + // Set up tabs + ActionBar actionBar = getSupportActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + actionBar.setDisplayShowTitleEnabled(false); - FragmentManager fragmentManager = getSupportFragmentManager(); - FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); - feedlist = new FeedlistFragment(); - fragmentTransaction.replace(R.id.main_fragment, feedlist); - fragmentTransaction.setTransition( - FragmentTransaction.TRANSIT_FRAGMENT_OPEN); - fragmentTransaction.commit(); - + Tab tab = actionBar.newTab() + .setText(getText(R.string.feeds_label).toString()) + .setTabListener(new TabListener( + this, getText(R.string.feeds_label).toString(), FeedlistFragment.class)); + + actionBar.addTab(tab); + tab = actionBar.newTab() + .setText("Playlist") + .setTabListener(new TabListener( + this, "Playlist", FeedlistFragment.class)); + actionBar.addTab(tab); } + + + /** TabListener for navigating between the main lists. */ + private class TabListener implements ActionBar.TabListener { + + private final Activity activity; + private final String tag; + private final Class fClass; + private Fragment fragment; + + public TabListener(Activity activity, String tag, Class fClass) { + this.activity = activity; + this.tag = tag; + this.fClass = fClass; + } + + public void onTabSelected(Tab tab, FragmentTransaction ft) { + if (fragment == null) { + fragment = Fragment.instantiate(activity, fClass.getName()); + ft.replace(R.id.main_fragment, fragment); + } else { + ft.attach(fragment); + } + } + + public void onTabUnselected(Tab tab, FragmentTransaction ft) { + if (fragment != null) { + ft.detach(fragment); + } + } + + public void onTabReselected(Tab tab, FragmentTransaction ft) { + // Do nothing + } + } }