Back to project page ActionBarSherlock-Custom-Menu-List-Navigation-Fragments.
The source code is released under:
Apache License
If you think the Android project ActionBarSherlock-Custom-Menu-List-Navigation-Fragments 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.androidbegin.absnavlist; /* w ww .j a v a2 s .com*/ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.widget.ListView; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.OnNavigationListener; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; public class MainActivity extends SherlockFragmentActivity { // Declare Variables ListView list; NavListAdapter adapter; String[] title; String[] subtitle; int[] icon; Fragment fragment1 = new Fragment1(); Fragment fragment2 = new Fragment2(); Fragment fragment3 = new Fragment3(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Generate title title = new String[] { "Title Fragment 1", "Title Fragment 2", "Title Fragment 3" }; // Generate subtitle subtitle = new String[] { "Subtitle Fragment 1", "Subtitle Fragment 2", "Subtitle Fragment 3" }; // Generate icon icon = new int[] { R.drawable.action_about, R.drawable.action_settings, R.drawable.collections_cloud }; // Pass results to NavListAdapter Class adapter = new NavListAdapter(this, title, subtitle, icon); // Hide the ActionBar Title getSupportActionBar().setDisplayShowTitleEnabled(false); // Create the Navigation List in your ActionBar getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); // Listen to navigation list clicks ActionBar.OnNavigationListener navlistener = new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int position, long itemId) { FragmentTransaction ft = getSupportFragmentManager() .beginTransaction(); // Locate Position switch (position) { case 0: ft.replace(android.R.id.content, fragment1); break; case 1: ft.replace(android.R.id.content, fragment2); break; case 2: ft.replace(android.R.id.content, fragment3); break; } ft.commit(); return true; } }; // Set the NavListAdapter into the ActionBar Navigation getSupportActionBar().setListNavigationCallbacks(adapter, navlistener); } // Not using options menu in this tutorial @Override public boolean onCreateOptionsMenu(Menu menu) { getSupportMenuInflater().inflate(R.menu.activity_main, menu); return super.onCreateOptionsMenu(menu); } }