How to Call Activity using ListView Array

后端 未结 2 609
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 08:09

Iam using Sherlock fragment to make a Action Bar. and I have ListView in action bar, but I will my listview can call activity .. Please help me Thanks.. :)

in this code

2条回答
  •  星月不相逢
    2021-01-28 08:31

    List navigation in the ActionBar does not require a ListFragment (or a SherlockListFragment in your case). Your code is setting the adapter for the ListView that is the content of the Activity. What you want is to set the ActionBar's navigation mode and provide the adapter to the ActionBar. In your onCreate:

    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setListNavigationCallbacks(adapter, navigationListener);
    

    adapter is a SpinnerAdapter implementation. navigationListener is a ActionBar.OnNavigationListener implementation. When the user presses an item from the dropdown list in the ActionBar, your navigationListener's onNavigationItemSelected method gets called and it passes in the position and the id of the selected item. In that callback you can implement starting another activity.

    See ActionBar and ActionBar.OnNavigationListener -- ActionBarSherlock mirrors the standard Android ActionBar APIs.

提交回复
热议问题