Changes

Jump to: navigation, search
4.b. Add Image to the Menu
4.b.1. Run the application. Click on the menu you should see the following:<br/>
[[Image: BB_Menu.png | 300px]]<br/>
<source lang="java">
 
/**
* Concrete implementation of abstract class MenuItem
*/
class ImageMenuItem extends MenuItem
{
/**
* Creates a new MenuDemoMenuItem object
*/
ImageMenuItem(String title, int ordinal, int property, int num)
{
super(new StringProvider(title), ordinal, property);
 
// Create Image object from project resource
Bitmap bitmap;
switch(num)
{
case 0:
bitmap = Bitmap.getBitmapResource("add.png");
break;
case 1:
bitmap = Bitmap.getBitmapResource("edit.png");
break;
case 2:
bitmap = Bitmap.getBitmapResource("delete.png");
break;
case 3:
bitmap = Bitmap.getBitmapResource("email.png");
break;
case 4:
bitmap = Bitmap.getBitmapResource("map.png");
break;
default:
bitmap = Bitmap.getBitmapResource("none.png");
break;
}
Image image = ImageFactory.createImage(bitmap);
 
// Set image as this menu item's icon
setIcon(image);
}
}
</sourse>
1
edit

Navigation menu