码迷,mamicode.com
首页 > 移动开发 > 详细

Android ActionBar下拉选项

时间:2014-05-12 15:44:57      阅读:398      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   class   code   java   

bubuko.com,布布扣

bubuko.com,布布扣
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;
    }

}
bubuko.com,布布扣

 actionBar.setListNavigationCallbacks(spinnerAdapter, this);
这个ArrayAdapter是继承于BaseAdapter的,而BaseAdapter又实现了SpinnerAdapter接口.

Android ActionBar下拉选项,布布扣,bubuko.com

Android ActionBar下拉选项

标签:android   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/wuyou/p/3704132.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!