Android actionbar drop-down options

Source: Internet
Author: User

 Packagecom.example.actionBarTest.actionBarList;ImportAndroid.app.ActionBar;Importandroid.app.Activity;Importandroid.app.Fragment;ImportAndroid.os.Bundle;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.SpinnerAdapter;ImportCOM.EXAMPLE.ACTIONBARTEST.R;Importjava.util.ArrayList;Importjava.util.List;/*** Created by Heyiyong on 2014-5-2 morning 9:50.*/ Public classListnavigationactivityextendsActivityImplementsActionbar.onnavigationlistener {PrivateList<fragment>fragments; PrivateString[] Navs = {"Add", "delete", "edit", "Query", "more"}; PrivateSpinneradapter Spinneradapter;  Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.tab_main); Spinneradapter=NewArrayadapter<string> ( This, Android.        R.layout.simple_list_item_1, Navs); Homefragment homefragment=Newhomefragment (); Musicfragment musicfragment=Newmusicfragment (); Videofragment videofragment=Newvideofragment (); Fragments=NewArraylist<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 BooleanOnnavigationitemselected (intItemposition,LongitemId) {System.out.println ("Itemposition =" +itemposition);        Getfragmentmanager (). BeginTransaction (). replace (R.id.tab_main, Fragments.get (itemposition)). commit (); return true; }}

Actionbar.setlistnavigationcallbacks (Spinneradapter, this);
This arrayadapter is inherited from the Baseadapter, and Baseadapter realizes the Spinneradapter interface.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.