安卓:福尔摩斯的动作栏下拉 [英] Android: Sherlock action bar drop down

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

问题描述

我想实现一个下拉列表导航在Android的操作栏。 我可以看到下拉列表中的项目,但我不能让点击事件。

I'm trying to implement a drop down list as navigation for the action bar in Android. I can see the drop down list and the items, but I can't get the clicking event.

我不知道我错过了什么,因为我是按照<一个教程href="http://developer.android.com/guide/topics/ui/actionbar.html">http://developer.android.com/guide/topics/ui/actionbar.html

I'm not sure what I'm missing since I was following the tutorial in http://developer.android.com/guide/topics/ui/actionbar.html

这是我的code:

public void onCreate(Bundle savedInstanceState) {
        OnNavigationListener mOnNavigationListener;
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.info_layout);
        // getSupportActionBar().setHomeButtonEnabled(true);
         getSupportActionBar().setDisplayShowTitleEnabled(false);

        getSupportActionBar().setNavigationMode(getSupportActionBar().NAVIGATION_MODE_LIST);
        SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.navigation_array, android.R.layout.simple_dropdown_item_1line);
        mOnNavigationListener = new OnNavigationListener() {
            public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                switch (itemPosition) {
                case 1:
                    Intent i = new Intent();
                    i.setClass(getApplicationContext(), ZoekAndBoekActivity.class);
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                }
                // return super.onOptionsItemSelected(itemPosition);
                return true;
            }
        };
        getSupportActionBar().setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);
    }

感谢很多提前!

Thanks a lot in advance!

推荐答案

你确定你没有得到点击事件?您正在创建的意图,但没有用它做什么。尝试是这样的:

Are you sure that you don't get click events? You're creating intent but doesn't do anything with it. Try something like this:

switch (itemPosition) {
    case 1:
        Intent i = new Intent();
        i.setClass(getApplicationContext(), ZoekAndBoekActivity.class);
        startActivity(i);
        break;
    ...
}

或添加书面记录,以确保:

or add writing to log to be sure:

public boolean onNavigationItemSelected(int itemPosition, long itemId) {
    Log.d("SomeTag", "Get click event at position: " + itemPosition);
    switch (itemPosition) {
        ...
    }
}

和看到logcat的输出与SomeTag消息,当你点击的项目。

and see in the logcat output for message with "SomeTag" when you click on items.

这篇关于安卓:福尔摩斯的动作栏下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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