I have in my application a ListView activity called ResultListViewActivity and which display contents from a database. The content displayed in the listview depends on a button clicked in a previous activity. So if the user clicks the "Button 1" in the Main Activity, it will display a specific content in ResultListViewActivity, and so on.
I want to add a menu to this activity : the thing is, the items of this menu are also supposed to change according to the button clicked before. There are 9 cases, each cases has a different number of items. So far I have this code :
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Bundle bundle = getIntent().getExtras();
int filterVariable = bundle.getInt("filterVariable");
switch (filterVariable)
{
case 1:
getSupportMenuInflater().inflate(R.menu.filter_fastfood, menu);
break;
case 2:
getSupportMenuInflater().inflate(R.menu.filter_restaurants, menu);
break;
case 3:
getSupportMenuInflater().inflate(R.menu.filter_coffeeshops, menu);
break;
case 4:
getSupportMenuInflater().inflate(R.menu.filter_bars, menu);
break;
// [... and so on]
}
return super.onCreateOptionsMenu(menu);
}
It works well, for every case I indeed have my different items in the menu. But I don't want these items to be reachable through the "menu button" of my device (which is absolutely not instinctive and hard for the user to guess). These items are importants so I would like to have a button on the upper right corner, which would open this menu instead (drop down menu / pop up menu).
Do you know how such a thing can be done ? I have seen this in some google application but couldn't find tutorial showing which tools to use for doing this.
Thanks !
ps: I am using actionbarsherlock in my application.