How to Call Activity using ListView Array

后端 未结 2 585
隐瞒了意图╮
隐瞒了意图╮ 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:16

    You need to use setOnItemClickListener() on your listview

      listview.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> arg0,View arg1, int position, long arg3) {
        Intent n = null; 
        switch (position){
           case 0: 
             n = new Intent(getActivity(), Class0.class);
             break;
           case 1: 
             n = new Intent(getActivity(), Class1.class);
             break;
        }
        if(null!=n)
          startActivity(n);
      }
    }); 
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题