I'm using the NavigationDrawer in my app and replace the fragment when clicking a item in the drawer. My problem I have is that the menu items in the ActionBar are not updated when I change the fragment.
I've followed this tutorial https://www.grokkingandroid.com/adding-action-items-from-within-fragments/ closely but it's still not working in my app.
Adding some code snippets of the parent activity and one of the Fragments here.
What I need is to display the other menu items of the contact form fragment (R.menu.contactform_send_menu) when the initial fragment gets replaced with ContactFormFragment.java.
public class MainActivity extends FragmentActivity implements ActionBar.OnNavigationListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle(R.string.app_name);
// Set up the action bar to show a dropdown list.
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
createNavigationDrawer(savedInstanceState);
}
private final int DRAWER_MAIN = 0;
private final int DRAWER_CONTACT = 5;
// update the main content by replacing fragments
private void selectItem(int position) {
Fragment fragment = null;
Bundle args = new Bundle();
boolean isFragment = false;
switch (position) {
case DRAWER_MAIN:
fragment = new WelcomeSectionFragment();
args.putString(WelcomeSectionFragment.ITEM_NAME, dataList.get(position).getItemName());
args.putInt(WelcomeSectionFragment.IMAGE_RESOURCE_ID, dataList.get(position).getImgResID());
getActionBar().setTitle(R.string.app_name);
isFragment = true;
break;
case DRAWER_CONTACT:
fragment = new ContactFormFragment();
args.putString(ContactFormFragment.ITEM_NAME, dataList.get(position).getItemName());
args.putInt(ContactFormFragment.IMAGE_RESOURCE_ID, dataList.get(position).getImgResID());
getActionBar().setTitle(R.string.contactform_title);
isFragment = true;
break;
default:
break;
}
if (isFragment) {
fragment.setArguments(args);
FragmentManager frgManager = getFragmentManager();
frgManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
setTitle(dataList.get(position).getItemName());
mDrawerLayout.closeDrawer(mDrawerList);
}
}
}
and the fragment:
public class ContactFormFragment extends Fragment {
public ContactFormFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ca = getActivity();
Reachability.registerReachability(ca.getApplicationContext());
settings = ca.getSharedPreferences(Konstanten.PREFERENCES_FILE, 0);
member = new Gson().fromJson(settings.getString(Konstanten.MEMBER_OBJECT, null), Member.class);
latoFontLight = Tools.getFont(ca.getAssets(), "Lato-Light.ttf");
latoFontBold = Tools.getFont(ca.getAssets(), "Lato-Bold.ttf");
// Update action bar menu items?
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Do something that differs the Activity's menu here
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
if (Build.VERSION.SDK_INT >= 11) {
// selectMenu(menu);
inflater.inflate(R.menu.contactform_send_menu, menu);
}
}
}
When debugging I can see that setHasOptionsMenu(true); gets called in onCreate() and I also get into the onCreateOptionsMenu() of ContactFormFragment.java. I just don't understand why the action bar keeps its initial menu items and doesn't replace them. What am I missing?
Thanks for any help.
Try putting setHasOptionsMenu(true); inside the onCreateView()of your ChildFragment.java
I don't see one in the code you posted.
I got it working! The problem I had was that I added a custom drop down menu to the main fragment. So each time I change the fragment through the drawer navigation I manually have to remove that drop down menu and when returning to the main fragment I will re-add it.
Here is what I did:
In the parent activity:
MainActivity.java:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.signin_menu, menu);
getMenuInflater().inflate(R.menu.clear_search_history_menu, menu);
// Search
// Associate searchable configuration with the SearchView
getMenuInflater().inflate(R.menu.search_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
getMenuInflater().inflate(R.menu.signin_menu, menu);
getMenuInflater().inflate(R.menu.clear_search_history_menu, menu);
// Search
// Associate searchable configuration with the SearchView
getMenuInflater().inflate(R.menu.search_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
// If the nav drawer is open, hide action items related to the content
// view
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.search).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
// This is the selection of the drawer (stripped some code to keep it short)
private void selectItem(int position) {
Fragment fragment = null;
Bundle args = new Bundle();
boolean isFragment = false;
ActionBar actionBar = getActionBar();
switch (position) {
case DRAWER_MAIN:
fragment = new WelcomeSectionFragment();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(new GameSystemsAdapter(getActionBarThemedContextCompat(), allSystemsPlusEmpty), this);
actionBar.setTitle(R.string.app_name);
isFragment = true;
break;
case DRAWER_FAVORITES:
fragment = new FavoritesMainFragment();
// Remove System-Select Drop-Down
actionBar.setListNavigationCallbacks(null, null);
actionBar.setNavigationMode(0);
actionBar.setTitle(R.string.favorites);
isFragment = true;
break;
case DRAWER_TOP_MEMBERS:
fragment = new TopMembersFragment();
// Remove System-Select Drop-Down
actionBar.setListNavigationCallbacks(null, null);
actionBar.setNavigationMode(0);
actionBar.setTitle(R.string.top_members_top_helping);
isFragment = true;
break;
default:
break;
}
if (isFragment) {
fragment.setArguments(args);
FragmentManager frgManager = getFragmentManager();
frgManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
setTitle(dataList.get(position).getItemName());
mDrawerLayout.closeDrawer(mDrawerList);
}
}
and here the part of the fragment(s):
ChildFragment.java
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if (Build.VERSION.SDK_INT >= 11) {
selectMenu(menu);
}
}
#Override
public void onPrepareOptionsMenu(Menu menu) {
selectMenu(menu);
}
private void selectMenu(Menu menu) {
parentActivity.getMenuInflater().inflate(R.menu.contactform_send_menu, menu);
}
If there are any better solutions I'm very interested in your ideas.
There are two cases to consider:
You want all action items to come from within fragments exclusively.
You also have action items that should be global and are defined within the activity.
Let's begin with option 2 since it's the most common case.
If you have fragment specific items and global items at the same time, you do not want to use onCreateOptionsMenu() within the fragment. The reason is that it would look weird - even if it worked. The fragment actions would be added right after creating the fragment, while the global items would be added after the drawer has closed (by default). I think no user would like that.
What you could do to still let the fragment decide which items to display is to create an interface for all fragments to implement. This could define one method which would return the menu id for the menu to inflate or -1 if no menu should be inflated.
In case of option 1, I can only assume that you clear() the menu within the Activity's onCreateOptionsMenu(). Otherwise it wouldn't delete the fragments' menu entries. So just get rid of the clear() and all should be fine.
Related
I have implemented SearchView inside one of a Fragment of Tablayout. It is working fine(show/hide) when switching between tablayout fragments.
My issue is that I have a HomeActivity in which I have implemented NavigationDrawer in one of a Fragment I have added TabLayout and in one of TabLayout Fragment I have added SearchView. Issue occurs when I am switching from Fragment which has a SearchView to Fragment from NavDrawer.
Searchview remains up there in other fragments too and when I switch back to that fragment in which I have added searchView then that fragment add one more searchview over Toolbar.
Here's my code from Fragment which as a SearchView
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
setHasOptionsMenu(true);
....
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_search, menu);
LogUtils.LOGI("menu added", "menu");
// Associate searchable configuration with the SearchView
//SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
//SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
//searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
final MenuItem item = menu.findItem(R.id.search);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String query) {
LogUtils.LOGI("Search filter", query);
final ArrayList<EventModel> filteredModelList = filter(allEventseventsArrayList, query);
allEventsListAdapter.animateTo(filteredModelList);
eventbriteListRecyclerView.scrollToPosition(0);
return true;
}
});
searchView.setOnSearchClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LogUtils.LOGI("Search", "Search Expands");
titleIconImageView.setVisibility(View.GONE);
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
#Override
public boolean onClose() {
LogUtils.LOGI("Search", "Search Collapse");
titleIconImageView.setVisibility(View.VISIBLE);
return false;
}
});
MenuItemCompat.setOnActionExpandListener(item,
new MenuItemCompat.OnActionExpandListener() {
#Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
// Return true to allow the action view to expand
titleIconImageView.setVisibility(View.GONE);
LogUtils.LOGI("Menu", "Menu Expands");
return true;
}
#Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
// When the action view is collapsed, reset the query
LogUtils.LOGI("Menu", "Menu Collapse");
titleIconImageView.setVisibility(View.VISIBLE);
// Return true to allow the action view to collapse
return true;
}
});
super.onCreateOptionsMenu(menu, inflater);
}
Fragment code in which I don't want SearchView
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
setHasOptionsMenu(false);
....
}
I haven't added any code related to menu in activity.
First run Image with searchView
Image after switching to different fragment from navMenu
Image again switching to fragment which has menu
It's a bit hacky but I solved it by setting setHasOptionsMenu to true and clearing the Menu in onCreateOptionsMenu via
public void onCreateOptionsMenu (Menu menu, MenuInflater inflater){
menu.clear()
}
I am building a calculator app using fragment and I want the calculator fragment to show back when the back button is pressed on the menu item fragment. I have been using the addToBackStac(null) but it is not working for me.
Here is my code below
public class MainActivity extends ActionBarActivity {
FragmentManager fragmentManager;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState == null){
fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction().addToBackStack(null);
CalculatorFragment calc = new CalculatorFragment();
fragmentTransaction.add(R.id.relLejaut, calc);
fragmentTransaction.commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.item) {
About about= new About();
// Insert the fragment by replacing any existing fragment
fragmentManager.beginTransaction().addToBackStack(null).replace(R.id.relLejaut, about).commit();
return true;
}
return super.onOptionsItemSelected(item);
}
}
You need to first add() or replace() a fragment in FragmentTransaction and then call addToBackStack() for it to work.
Call it this way:
fragmentManager.beginTransaction().replace(R.id.relLejaut,about).addToBackStack(null).commit();
I have an ActionBar activity with a FrameLayout and a menu. when the user clicks the menu item I replace the fragment with the relevant new fragment. However, I cannot see an obvious way to remove the menu item for the selected fragment.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
StudyFragment startFragment = new StudyFragment();
startFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction().add
(R.id.container, startFragment).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_study:
replaceFragment((Fragment)new StudyFragment());
break;
case R.id.action_list:
replaceFragment((Fragment)new ListFragment());
break;
// etc
}
return super.onOptionsItemSelected(item);
}
private void replaceFragment(Fragment f) {
FragmentTransaction transaction =
getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container, f);
transaction.addToBackStack(null);
transaction.commit();
}
The Google documentation on changing menus says to disable the menu in onPrepareOptionsMenu - but how will I know which item has been selected?
--Solution Implemented--
Using Muhammed Refaat's solution below I added two new members to the class:
private Menu activityMenu;
private MenuItem curMenuItem;
Set them in onCreateOptionsMenu
activityMenu = menu;
curMenuItem = activityMenu.findItem(R.id.action_study);
curMenuItem.setVisible(false);
And changed them on onOptionsItemSelected
curMenuItem.setVisible(true);
curMenuItem = activityMenu.findItem(id);
curMenuItem.setVisible(false);
First get the item you want to remove :
MenuItem item = menu.findItem(R.id.your_action);
then set it's Visibility false :
item.setVisible(false);
and if the problem is in getting the menu (as it's not in the fragment), you can easily get a context from the activity that contains the menu and get the menu by it.
Inside your fragment you will have to use setHasOptionsMenu(true); in order to access options menu from within your fragment.
Code (inside your second fragment where you wanna hide the item):
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// TODO your code to hide item here
super.onCreateOptionsMenu(menu, inflater);
}
Similarly, for your fragment where you want to show that MenuItem you can do the similar thing.
In the fragment where you want to hide the Item
#Override
public void onPrepareOptionsMenu(Menu menu) {
MenuItem item=menu.findItem(R.id.action_search);
item.setVisible(false);
and in onCreate() of your fragment
setHasOptionsMenu(true);
Adding to Muhammed's answer above. Once the item has been set as invisible, you may need to also disable the item. Note Google's comment: "Even if a menu item is not visible, it may still be invoked via its shortcut (to completely disable an item, set it to invisible and disabled)" under setVisible() in the MenuItem documentation.
Thus:
item.setVisible(false);
item.setEnabled (false);
Add below codes into your fragment
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
MenuItem item = menu.findItem(R.id.save);
item.setVisible(false);
}
// create Boolean variable in the main activity
private var menuvisibile: Boolean = true
// while navigating fragments set the menuvisibile value and use it
// variable as part of the return statement
invalidateOptionsMenu()
menuvisibile = false
override fun onCreateOptionsMenu(menu: Menu?): Boolean
{
val menuInflater = menuInflater
menuInflater.inflate(R.menu.notification,menu)
return menuvisibile
}
working well for me.
I am working with the support library ActionBar because I'm using an older minimum SDK. In the activity, I am using FragmentTabHost because I have 3 tabs. The ActionBar also has a SearchView, so when a search is made, the 3rd tab is switched out with the results of the search.
I am able to get intput from the SearchView, but I am unable to switch out the 3rd tab when I have a search result. I am using this as an example:
Dynamically changing the fragments inside a fragment tab host?
My problem is that when I try to get a reference to the 3rd tab, and I use getSupportFragmentManager().findFragmentByTag() , the fragment being returned is always null.
My base container that helps in swapping multiple fragments in a tab:
public class BaseContainerFragment extends Fragment{
public void replaceFragment(Fragment fragment, boolean addToBackStack) {
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
if (addToBackStack) {
transaction.addToBackStack(null);
}
transaction.replace(R.id.container_framelayout, fragment);
transaction.commit();
getChildFragmentManager().executePendingTransactions();
}
public boolean popFragment() {
//Log.e("test", "pop fragment: " + getChildFragmentManager().getBackStackEntryCount());
boolean isPop = false;
if (getChildFragmentManager().getBackStackEntryCount() > 0) {
isPop = true;
getChildFragmentManager().popBackStack();
}
return isPop;
}
}
A container that extends BaseContainerFragment
public class LibraryContainerFragment extends BaseContainerFragment {
private boolean mIsViewInited;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.e("test", "tab 1 oncreateview");
return inflater.inflate(R.layout.container_fragment, null);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.e("test", "tab 1 container on activity created");
if (!mIsViewInited) {
mIsViewInited = true;
initView();
// setRetainInstance(true);
}
}
private void initView() {
Log.e("test", "tab 1 init view");
replaceFragment(new LibraryFragment, false);
}
}
The xml used to switch out fragments (container_fragment.xml):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
My main activity:
public class BookSetup extends ActionBarActivity {
// For accessing SlidingMenu library
private SlidingMenu slidingMainMenu;
private FragmentTabHost mTabHost;
private SlidingMenu slidingContextMenuFavourites;
private SlidingMenu slidingContextMenuMyPrayerBook;
private SlidingMenu slidingContextMenuLibrary;
private android.support.v4.app.FragmentManager fragmentManager;
LibraryContainerFragment libraryContainerFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Settings for the clickable top-left button in the action bar
android.support.v7.app.ActionBar bar = getSupportActionBar();
bar.setDisplayHomeAsUpEnabled(false);
bar.setHomeButtonEnabled(true);
bar.setIcon(R.drawable.main_menu);
// Setting up tabbed navigation
bar.setDisplayShowTitleEnabled(false);
// Setting up tabs
fragmentManager = getSupportFragmentManager();
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, fragmentManager, R.id.realtabcontent);
// Add tabs
mTabHost.addTab(mTabHost.newTabSpec("Favourites").setIndicator(getString(R.string.favourites) ),
FavouritesFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("My Book").setIndicator(getString(R.string.my_book) ),
MyBookFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("Library").setIndicator(getString(R.string.library) ),
LibraryContainerFragment.class, null);
mTabHost.setCurrentTab(2);
//mTabHost.
// Creates a sliding animation when activity is started
overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_to_left);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu_with_search_context_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
//SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
final MenuItem searchMenuItem = menu.findItem(R.id.action_search);
searchView = (android.support.v7.widget.SearchView) MenuItemCompat.getActionView(searchMenuItem);
//searchView = (SearchView)menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
//searchView.requestFocus();
searchView.requestFocusFromTouch();
//searchView.setIconifiedByDefault(true);
// Listener for the search input found in the action bar, when the magnifying glass is
// clicked
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
// Activated when a search string is submitted
#Override
public boolean onQueryTextSubmit(String query) {
// TODO : query is the text from the search view after you clicked search
if(query != null){
// If results are found, then switch the fragments
if(!sectionsFound.isEmpty()){
// Initialize the search fragment and send bundles of data to it
SearchLibraryResultFragment fragment = new SearchLibraryResultFragment();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("values",
(ArrayList<? extends Parcelable>) sectionsFound);
bundle.putStringArrayList("names", sectionNames);
fragment.setArguments(bundle);
mTabHost.setCurrentTab(2);
libraryContainerFragment = (LibraryContainerFragment)fragmentManager.findFragmentByTag("Library");
((BaseContainerFragment) libraryContainerFragment.getParentFragment() ).replaceFragment(fragment,true );
return true;
}
});
}
}
This is the line that always returns null in BookSetup.java:
((BaseContainerFragment) libraryContainerFragment.getParentFragment() ).replaceFragment(fragment,true );
You are using the ChildFragmentManager to replace your Fragments right?
That might be your problem, instead of
libraryContainerFragment = (LibraryContainerFragment)fragmentManager.findFragmentByTag("Library");
use
libraryContainerFragment = (LibraryContainerFragment) getChildFragmentManager().findFragmentByTag("Library");
I am using the ActionBar drop-down navigation with OnNavigationListener implemented.
The requirement is to fire the onNavigationItemSelected() method every time, also when the same drop-down item is selected. The default Android implementation prevents the onNavigationItemSelected() method from running when the same item is selected.
I have seen the solutions to this requirement only for the standard Spinner implementation here and here, however not for the specific ActionBar drop-down navigation implementation.
Any suggestions how to overcome this default Android behaviour would be most appreciated.
Here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPosition = -1;
actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
....
and
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.eventmenu, menu);
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.s_events,
android.R.layout.simple_spinner_dropdown_item);
OnNavigationListener mOnNavigationListener = new OnNavigationListener() {
#Override
public boolean onNavigationItemSelected(int position, long itemId) {
if (mPosition > -1) { // to prevent opening the data entry fragment when the Events fragment is initially opened
...
startActivity(newEvent);
}
mPosition = position;
return true;
}
};
actionBar.setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);
return true;
}