设置下拉的动作栏项目 [英] Setting the dropdown for the action bar item

查看:85
本文介绍了设置下拉的动作栏项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置的动作栏和物品被跌破code和相应的此搜索显示。当用户点击显示书签屏幕操作项,它转到其他活动。在该活动我想另一个项目(选择输入书签)将显示在显示书签屏幕的地方。所以,我想用抽象类通过将相应的东西,真的还是假的,如下图所示对其进行管理。但现在我无法得到两件事情。

I am setting the action bar and item by the below code and the respective image1 is shown. When the user clicks on show bookmark screen action item, it goes to other activity. In that activity I want another item(SELECT BOOKMARK TYPE ) to be displayed in the place of SHOW BOOKMARK SCREEN. So I am thinking to managing it with abstract class by setting the respective things to true or false as shown below. But now I am unable to get two things.

1)如何在0的情况下为行动项目区分?因为我更换操作项彼此。

1) How to differentiate in case 0 for both action items? as I am replacing the action item with one another.

2)如何获得下拉为选择输入书签作为在图片完全显示2

2)How to get the dropdown for that SELECT BOOKMARK TYPE as exactly shown in the image 2.

见过几个帖子,但我有点新的机器人,我无法理解,并把它通过增加额外的code到我的present code完成。能否请您帮助我在这? code片段是AP preciated。先谢谢了。

Have seen few posts, but as I am somewhat new to android, I am unable to understand and get it done by adding the extra code to my present code. Can you please help me on this? Code snippets are appreciated. Thanks in advance.

public abstract class ActionActivity extends SherlockActivity {
    protected boolean mIsShowBookmarkScreen = true;


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

         if(mIsShowBookmarkScreen)
         {
             menu.add("SHOW BOOKMARK SCREEN")
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
         }

         else 
         {
             menu.add(SELECT BOOKMARK TYPE);
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
         }

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        //This uses the imported MenuItem from ActionBarSherlock
        switch(item.getItemId())
        {

        case 0:
            Intent intent = new Intent(ActionActivity.this,BookmarkScreen.class);
            startActivity(intent);
            return true;
        }
        return false;
    }

     @Override
        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            getSupportActionBar().setHomeButtonEnabled(true);
        }

}

图片1:

图片2:

目前至少有人可以帮上实现第二个。我得到了第一个问题的想法。

At least can someone please help on achieving second one. I got an idea on 1st problem.

推荐答案

1)通过区分的instanceof

if (this instanceof ActivityA) {
    // start Intent A
} else if (this instanceof ActivityB) {
    // start Intent B
}

2)添加微调为自定义而ActionView

<string-array name="items">
    <item>SELECT BOOKMARK TYPE</item>
    <item>TYPE-1</item>
    <item>TYPE-2</item>
    <item>TYPE-3</item>
</string-array>

MenuItem spinnerItem = menu.add(null);
spinnerItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
IcsSpinner spinner = new IcsSpinner(this, null);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
        this, R.array.items, R.layout.sherlock_spinner_item);
adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
        LayoutParams.MATCH_PARENT));
spinnerItem.setActionView(spinner);

请注意,我用的那种私人 IcsSpinner 这里创建相同的外观上的SDK版本&LT; 4.0。看到这个回答了解详细信息。

Note that I am using the kind of private IcsSpinner here to create the same look on SDK Version < 4.0. See this answer for details.

如果您想进一步定制微调,你可能需要创建自己的适配器

If you want to further customize the Spinner, you will probably need to create your own Adapter.

这篇关于设置下拉的动作栏项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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