我对这个黑莓编程有点陌生......我想从位图和位图字段中制作自定义按钮,但是当我单击位图字段时,它总是首先显示菜单项(“打开”)然后执行运行方法.
我想让它可以点击,当我点击触控板时,它会执行运行方法(直接执行运行方法而不显示“打开”菜单),但我不知道如何做到这一点......
这是我的代码:
private void createFields()
{
Bitmap atas = Bitmap.getBitmapResource("banerputih.png");
add(new BitmapField(atas, Field.FIELD_HCENTER));
//separator
add(new SeparatorField());
Bitmap satu = Bitmap.getBitmapResource("wisata.png");
Bitmap dua = Bitmap.getBitmapResource("trasport.png");
Bitmap tiga = Bitmap.getBitmapResource("other.png");
Bitmap empat = Bitmap.getBitmapResource("aboutme.png");
Bitmap three = Bitmap.getBitmapResource("3.gif");
add( new BitmapField(satu, Field.FOCUSABLE | Field.FIELD_HCENTER |Field.HIGHLIGHT_FOCUS));
add(new BitmapField(dua, Field.FOCUSABLE | Field.FIELD_HCENTER | Field.HIGHLIGHT_FOCUS));
add(new BitmapField(tiga, Field.FOCUSABLE | Field.FIELD_HCENTER | Field.HIGHLIGHT_FOCUS));
add(new BitmapField(empat, Field.FOCUSABLE | Field.FIELD_HCENTER | Field.HIGHLIGHT_FOCUS));
add(new SeparatorField());
add(new BitmapField(three, Field.FIELD_HCENTER));
add(new SeparatorField());
//Disini ditambahin Gambar
//panjang 480 pixel
}
//menambahkan menu open TODO
MenuItem _openAction = new MenuItem("Open",100000,10)
{
public void run()
{
getValue();
}
};
//menu about TODO
MenuItem _AboutAction = new MenuItem("About",100,100)
{
public void run()
{
UiApplication.getUiApplication().pushScreen(new AboutScreen());
}
};
//method getValue();
protected void getValue()
{
Field f = getFieldWithFocus();
if (f instanceof BitmapField)
{
BitmapField b = (BitmapField)f;
b.getIndex();
//untuk cek index
//Dialog.alert(Integer.toString(b.getIndex()));
if (b.getIndex() == 2)
{
UiApplication.getUiApplication().pushScreen(new wisataScreen());
}
else if (b.getIndex()== 3)
{
UiApplication.getUiApplication().pushScreen(new TransportScreen());
}
else if (b.getIndex()== 4)
{
UiApplication.getUiApplication().pushScreen(new HotelScreen());
}else if (b.getIndex()== 5)
{
UiApplication.getUiApplication().pushScreen(new AboutScreen());
}
}
}
public void makeMenu(Menu m, int instance)
{
m.add(_openAction);
m.add(_AboutAction);
super.makeMenu(m, instance);
}
}