Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : programatically add id to an actionbar item

i m trying to set an id to an item of the actionbarsherlock, but i'm getting this "Cannot invoke setId(int) on the primitive type void"

    menu.add("new")
        .setIcon(R.drawable.icon_1)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
        .setId(R.id.newone);
like image 709
Methnani Bilel Avatar asked Dec 12 '22 18:12

Methnani Bilel


1 Answers

You have two problems, one setShowAsAction returns void, so you cannot chain another call on it.

Second, MenuItem has no setID method. You cannot change the id after the item is created. To set an ID, you have to do it in the [add method] from Menu2,

menu.add("new", myItemId, myOrder, "TEXT" )
        .setIcon(R.drawable.icon_1, )
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
like image 108
iagreen Avatar answered Dec 14 '22 08:12

iagreen