ActionBar Sherlock 菜单项 OnClick [英] ActionBar Sherlock Menu Item OnClick
本文介绍了ActionBar Sherlock 菜单项 OnClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是使用 Sherlock ActionBar 的新手,我已经让它在我的应用程序中运行,我在操作栏中有一个项目,但我不知道如何让项目在点击时执行某些操作,我得到的就是这个.
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 :)
编辑
嘿,我在这个线程的帮助下使它工作了 我发现并做了一些更改,这是代码!:DDD
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);
}
}
推荐答案
试试这个,它有效:
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.layout.menu, menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.settings:
Intent i=new Intent(class1.this, clas2.class);
startActivity(i);
return true;
}
return false;
}
这篇关于ActionBar Sherlock 菜单项 OnClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文