Note that there are some explanatory texts on larger screens.

plurals
  1. POhow we can add menu item dynamically
    primarykey
    data
    text
    <p>hi frnds am creating an application which is a tab application.</p> <p>in my Home which extends sherlockFragmentActivity, i am inflating menu.xml and includes code for on optionMenuitem click listener. The Fragmentactivity contains tabhost and on each tab it load fragments. this is my menu.xml</p> <pre><code>&lt;item android:id="@+id/action_settings" android:orderInCategory="100" android:showAsAction="always" android:icon="@drawable/setting_selector" android:title="" &gt; &lt;menu &gt; &lt;item android:id="@+id/Profile" android:showAsAction="ifRoom" android:title="Profile"/&gt; &lt;item android:id="@+id/chngDoctor" android:showAsAction="ifRoom" android:title="Change doctor" android:visible="false"/&gt; &lt;item android:id="@+id/changePword" android:showAsAction="ifRoom" android:title="Change password"/&gt; &lt;item android:id="@+id/logout" android:showAsAction="ifRoom" android:title="Logout"/&gt; &lt;/menu&gt; &lt;/item&gt; </code></pre> <p>and this is my onCreateOptionMenu and onOptionItemSelected methods in class Home</p> <pre><code> @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub getSupportMenuInflater().inflate(R.menu.main, menu); SubMenu subMenu = (SubMenu) menu.getItem(0).getSubMenu(); if(userType.equals("admin")) subMenu.getItem(1).setVisible(true); else subMenu.getItem(1).setVisible(false); return true; } </code></pre> <p>and this is my onOptionItemSelected method</p> <pre><code> @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.Profile: break; case R.id.changePword : break; case R.id.chngDoctor : break; case R.id.logout: Home.this.finish(); break; } return true; } </code></pre> <p>i need to add some menus depending on tab change. that is on tab change i load different fragments and when fragment changes i need to add new items to the menu. my ListFrag which extends SherlockFragment and it will load when i click on the 3 rd tab. when this fragment load i need to add 1 menu item to the menu</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload