动作条福尔摩斯菜单项的OnClick [英] ActionBar Sherlock Menu Item OnClick

查看:189
本文介绍了动作条福尔摩斯菜单项的OnClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来使用夏洛克动作条,我已经让我的应用程序运行,我在动作条一个项目,但我不知道该怎么做的项目做一些事情时,它的点击我的一切是这样的

 公共布尔onCreateOptionsMenu(功能菜单){

    menu.add(文件夹)
        .setIcon(R.drawable.folder)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    返回true;
}


公共布尔onActionItemClicked(ActionMode模式,菜单项项){
        //我该怎么写吗?
    返回true;
 

我希望你明白我的意思:)

修改

嘿,我做了与这一点帮助<工作href="http://stackoverflow.com/questions/10278952/sherlockactionbar-adding-a-button-to-the-actionbar">thread我发现,我做了一些变化,这里是code! :DDD

  @覆盖
公共布尔onCreateOptionsMenu(功能菜单){
   com.actionbarsherlock.view.MenuInflater充气= getSupportMenuInflater();
   inflater.inflate(R.menu.menu,菜单);
   返回super.onCreateOptionsMenu(菜单);
}

@覆盖
公共布尔onOptionsItemSelected(菜单项项){
    //处理项目选择
    开关(item.getItemId()){
        案例R.id.search:
            完();
            返回true;
        案例R.id.new_folder:
            完();
            返回true;
        默认:
            返回super.onOptionsItemSelected(项目);
    }
}
 

解决方案

试试这个,它的工作原理:

 公共布尔onCreateOptionsMenu(com.actionbarsherlock.view.Menu菜单){
      com.actionbarsherlock.view.MenuInflater充气= getSupportMenuInflater();
      inflater.inflate(R.layout.menu,菜单);
}

公共布尔onOptionsItemSelected(菜单项项){
      //处理项目选择
      开关(item.getItemId()){
      案例R.id.settings:
          意图I =新的意图(class1.this,clas2.class);
          startActivity(ⅰ);
          返回true;
      }
      返回false;
}
 

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:

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;
}

这篇关于动作条福尔摩斯菜单项的OnClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆