首页 > 代码库 > Android ActionBar下拉选项
Android ActionBar下拉选项
package com.example.actionBarTest.actionBarList; import android.app.ActionBar; import android.app.Activity; import android.app.Fragment; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.SpinnerAdapter; import com.example.actionBarTest.R; import java.util.ArrayList; import java.util.List; /** * Created by Heyiyong on 2014-5-2 上午9:50. */ public class ListNavigationActivity extends Activity implements ActionBar.OnNavigationListener { private List<Fragment> fragments; private String[] navs = {"添加", "删除", "编辑", "查询", "更多"}; private SpinnerAdapter spinnerAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab_main); spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, navs); HomeFragment homeFragment = new HomeFragment(); MusicFragment musicFragment = new MusicFragment(); VideoFragment videoFragment = new VideoFragment(); fragments = new ArrayList<Fragment>(); fragments.add(homeFragment); fragments.add(musicFragment); fragments.add(homeFragment); fragments.add(videoFragment); fragments.add(homeFragment); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks(spinnerAdapter, this); } } @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { System.out.println("itemPosition = " + itemPosition); getFragmentManager().beginTransaction().replace(R.id.tab_main, fragments.get(itemPosition)).commit(); return true; } }
actionBar.setListNavigationCallbacks(spinnerAdapter, this);
这个ArrayAdapter是继承于BaseAdapter的,而BaseAdapter又实现了SpinnerAdapter接口.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。