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接口.
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。