Android: Sherlock’s action bar fell out

I am trying to implement a dropdown as a navigation for an action bar in Android. I see a dropdown and items, but I can not get the click event.

I'm not sure what I am missing, as I followed the tutorial at http://developer.android.com/guide/topics/ui/actionbar.html

This is my 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);
    }

Many thanks!

+5
source share
2 answers

Are you sure you did not receive click events? You create an intention, but do nothing with it. Try something like this:

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

or add a log entry:

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

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

+4
source

, , . , :)))

-1

All Articles