I am new to using the Sherlock ActionBar and I have make it run in my app and I have a item in the actionbar to but I don't know how to make the item do something when it's clicked all I got is this.
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Folder")
.setIcon(R.drawable.folder)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
//What do i write here?
return true;
I hope you understand what I mean :)
EDIT
Hey I made it work with a little help from this thread that I found and I made a few changes and here is the code! :DDD
@Override
public boolean onCreateOptionsMenu(Menu menu) {
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.search:
finish();
return true;
case R.id.new_folder:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Try this, it works:
Something like this (taken from one of my apps). The activity in this case extends
SherlockFragmentActivity
.The
R.id.ACTION_EXIT
is placed inres/values/ids.xml
[EDIT] Try this then (extends SherlockListActivity). You have to do some editing first. This code comes from the Sherlock demos. You should download them.
Please try this too.