Actionbar spinner-Usage Examples

Source: Internet
Author: User

Today needs to change a actionbar on the spinner font color, the results have not been solved for a long time, and finally found that he is in the code to add a TextView, and then use adapter loaded, not directly under the framework of the layout. Now summarize the use of spinner, see the following code directly

1) First, you need to have a spinneradapter to load the data with spinner.

 PrivateBaseadapter Mstackadapter =NewBaseadapter () {@Override Public intGetCount () {returnmState.stack.size (); } @Override PublicDocumentinfo GetItem (intposition) {            returnMState.stack.get (MState.stack.size ()-position-1); } @Override Public LongGetitemid (intposition) {            returnposition; } @Override PublicView GetView (intposition, View Convertview, ViewGroup parent) {            if(Convertview = =NULL) {Convertview=Layoutinflater.from (Parent.getcontext ()). Inflate (R.layout.item_title, parent,false); }            FinalTextView title =(TextView) Convertview.findviewbyid (Android.            R.id.title); FinalDocumentinfo doc =GetItem (position); if(Position = = 0) {                 FinalRootinfo root =Getcurrentroot ();            Title.settext (Root.title); } Else{title.settext (doc.displayname); }                //No padding when shown in ActionbarConvertview.setpadding (0, 0, 0, 0); returnConvertview; } @Override PublicView Getdropdownview (intposition, View Convertview, ViewGroup parent) {            if(Convertview = =NULL) {Convertview=Layoutinflater.from (Parent.getcontext ()). Inflate (R.layout.item_title, parent,false); }            FinalImageView subdir =(ImageView) Convertview.findviewbyid (R.id.subdir); FinalTextView title =(TextView) Convertview.findviewbyid (Android.            R.id.title); FinalDocumentinfo doc =GetItem (position); if(Position = = 0) {                FinalRootinfo root =Getcurrentroot ();                Title.settext (Root.title);            Subdir.setvisibility (View.gone); } Else{title.settext (doc.displayname);            Subdir.setvisibility (view.visible); }            returnConvertview; }    };

There are two more important methods.

One is GetView: This method is loaded with hints for prompt

One is Getdropview: This is for loading the dropdown box

2) Add Dropview Click to listen for events

    PrivateOnnavigationlistener Mstacklistener =NewOnnavigationlistener () {@Override Public BooleanOnnavigationitemselected (intItemposition,LongitemId) {            if(mignorenextnavigation) {mignorenextnavigation=false; return false; }                 while(MState.stack.size () > itemposition + 1) {mstate.stacktouched=true;            MState.stack.pop ();            } oncurrentdirectorychanged (ANIM_UP); return true; }        }; 

3) Add Spinneradapter and Dropview

-1);

Actionbar spinner-Usage Examples

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.