How to add an item to a menu group in NavigationView

前端 未结 3 590
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 03:30

In a word game for Android I currently have a hardcoded menu inflated from left_drawer_menu.xml and consisting of 3 groups (my turn, opponent turn and finally other

3条回答
  •  感动是毒
    2021-01-31 04:01

    menu.add(R.id.my_move, i, i, "Item " + i);
    

    You are also assigning the order (3rd param) as i. I am guessing that this is overriding the groupId. Try setting it as NONE as mentioned here

    menu.add(R.id.my_move, i, NONE, "Item " + i);
    

    Edit: Maybe something like this

    MenuItem lastItem = menu.findItem(R.id.);
    int lastOrder= lastItem.getOrder();
    menu.add(R.id.my_move, i, lastOrder-5, "Item " + i);
    

    Order is a combination of category and order, so it might not be as straight forward as this.

提交回复
热议问题