0

I have tried everything that i could have. gone through 6-7 articles except http://developer.android.com/ and things totally messed up i don't know what i am missing or taking the reference of wrong articles.

Here is my code:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >


<item
    android:id="@+id/userIcon"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:icon="@drawable/icon_user"
    android:title="@string/app_name"/>
<item
    android:id="@+id/listIcon"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:icon="@drawable/icon_list"
    android:title="@string/app_name"/>

<item
    android:id="@+id/menu_red"
    android:orderInCategory="1"
    android:showAsAction="ifRoom|withText"
    android:title="@string/get_back"/>

<item
    android:id="@+id/menu_green"
    android:orderInCategory="2"
    android:showAsAction="ifRoom|withText"
    android:title="@string/get_login"/>
</menu>

Activity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_product_list, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    case R.id.listIcon:
        Toast.makeText(this,
                "Menu list",
                Toast.LENGTH_LONG).show();

        break;
    case R.id.userIcon:
        Toast.makeText(this,
                "User Icon",
                Toast.LENGTH_LONG).show();
        break;
    }
    //return super.onOptionsItemSelected(item);
    return true;
}

Thanks a lot

rupesh
  • 2,865
  • 4
  • 24
  • 50

1 Answers1

0

Order in category determines the order appearance, from low to high check this link -> Set Item postition in ActionBar try the following code, but i'm not sure about in which order you want the menus to appear

<item
android:id="@+id/userIcon"
android:orderInCategory="1"
android:showAsAction="always"
android:menuCategory="system"
android:icon="@drawable/icon_user"
android:title="@string/app_name"/>

<item
android:id="@+id/listIcon"
android:orderInCategory="2"
android:showAsAction="always"
android:menuCategory="system"
android:icon="@drawable/icon_list"
android:title="@string/app_name"/>

<item
android:id="@+id/menu_red"
android:orderInCategory="99"
android:showAsAction="ifRoom|withText"
android:title="@string/get_back"/>

<item
android:id="@+id/menu_green"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="@string/get_login"/>
Community
  • 1
  • 1
Akbarsha
  • 2,422
  • 23
  • 34
  • I got my answer after doing a lot search. Anyway thanks @Emender – rupesh Dec 31 '13 at 08:48
  • So @rup35h , what was the problem ?! Please tell. – Fattie May 18 '14 at 10:15
  • 1
    @JoeBlow please have a look on this http://stackoverflow.com/questions/21328232/android-menu-option-not-appearing-in-android-4-4/21328362#21328362 – rupesh May 18 '14 at 10:20
  • @rup35h - thanks for the quick response! You know, I'm only on brand-new phones, so they should definitely show it. Indeed, note that the Open (physical) button also does NOT work. Sucks! Cheers ... – Fattie May 18 '14 at 10:50
  • 1
    @JoeBlow whick phone are you using ? – rupesh May 18 '14 at 11:16
  • Hi @rup35h .. I have a big selection of samsung, otc, moto., etc. I may have found the answer. It looks like surprisingly if **you do load the two libraries**, on 4.1+ only, it makes it not work. http://stackoverflow.com/a/23721321/294884 – Fattie May 18 '14 at 11:26
  • Yup, there's the solution! Note image ... stackoverflow.com/a/23721321/294884 – Fattie May 18 '14 at 11:43