android - How to pass my menu.xml to Sherlock actionBar in NAVIGATION_MODE_LIST -


i create actionbar library sherlock. work fine, i'll insert dropdownlist menu top of bar. examples construct drop down menu string array:

/** array of strings populate dropdown list */ string[] actions = new string[] {     "bookmark",     "subscribe",     "share" }; arrayadapter<string> adapter = new arrayadapter<string>(getbasecontext(),    r.layout.sherlock_spinner_item, actions); 

i would:

arrayadapter<string> adapter = new arrayadapter<string>(getbasecontext(),    r.layout.sherlock_spinner_item, r.menu.list_news); 

where r.menu.list_news:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" >   <item      android:id="@+id/classifica"     android:title="@string/classifica"     android:showasaction="withtext"         />  <item      android:id="@+id/next_match"     android:title="@string/next_match"     android:showasaction="withtext"         />  <item      android:id="@+id/risultati"     android:title="@string/risultati"     android:showasaction="withtext"         />  <item      android:id="@+id/top_ten"     android:title="@string/top_ten"     android:showasaction="withtext"         />  </menu> 

this activity.

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      /** create array adapter populate dropdownlist */     arrayadapter<string> adapter = new arrayadapter<string>(getbasecontext(),    r.layout.sherlock_spinner_item, my_menu_xml);       /** enabling dropdown list navigation action bar */     getsupportactionbar().setnavigationmode(com.actionbarsherlock.app.actionbar.navigation_mode_list);       /** defining navigation listener */     actionbar.onnavigationlistener navigationlistener = new onnavigationlistener() {          @override         public boolean onnavigationitemselected(int itemposition, long itemid) {             //toast.maketext(getbasecontext(), "current action : " + actions[itemposition]  , toast.length_short).show();             return false;         }     };      /** setting dropdown items , item navigation listener actionbar */     getsupportactionbar().setlistnavigationcallbacks(adapter, navigationlistener);             adapter.setdropdownviewresource(r.layout.sherlock_spinner_dropdown_item);      loaddata task = new loaddata();     task.execute(); } 

the example found here: http://wptrafficanalyzer.in/blog/adding-drop-down-navigation-to-action-bar-in-pre-honeycomb-versions-using-sherlock-library/

you need show list of text in drop down use below code .

mactionbar.setnavigationmode(actionbar.navigation_mode_list);         mactionbar.setdisplayhomeasupenabled(true);          marraydropdown=getresources().getstringarray(r.array.dropdown);          arrayadapter<string> madapter=new arrayadapter<string>(listnavactivity.this, android.r.layout.simple_spinner_item, marraydropdown);          madapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);          mactionbar.setlistnavigationcallbacks(madapter, this); 

here marraydropdown string array. although code compact libarary v7 similary sherlock one.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -