Android: programmatically add id to action bar item

im trying to set id for actionbarsherlock element, but I get this "Can't call setId (int) in void primitive type"

menu.add("new") .setIcon(R.drawable.icon_1) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM) .setId(R.id.newone); 
+4
source share
1 answer

You have two problems: one setShowAsAction returns void , so you cannot associate it with another call.

Secondly, MenuItem does not have a setID method. You cannot change the identifier after creating the item. To set the identifier, you must do this in the [ add ] method of Menu 2 ,

 menu.add("new", myItemId, myOrder, "TEXT" ) .setIcon(R.drawable.icon_1, ) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); 
+12
source

All Articles