Blackberry Storm - focus issue on bitmap field
in my screen there are 3 managers h1 h2 bmpf = new BitmapField
added in order like this as
backgroundmanager.add(h1)
backgroundmanager.add(bmpf)
backgroundmanager.add(h2)
add(background manager);
protected boolesn navigationClick()
{
int index1 = h1.getF开发者_开发问答ieldWithFocusIndex();
int index2 = h2.getFieldWithFocusIndex();
return true;
}
mow i get the focus index of all focussable fields in managers h1 and h2
but i cant get index of the bitnmapfield on focus i need to execute some code on its click
what to do
What for you need BitmapField index? Maybe it will be easier to declare BitmapField as a screen member? If you still will need index, call getIndex() from field.
class Scr extends MainScreen {
BitmapField mBitmapField;
protected boolean navigationClick(int status, int time) {
int bmpIndex = mBitmapField.getManager.getFocusedIndex();
return true;
}
}
UPDATE Other useful method in Field class is getManager():
class Scr extends MainScreen {
BitmapField mBitmapField;
protected boolean navigationClick(int status, int time) {
int index = -1;
Manager manager = mBitmapField.getManager();
if (manager != null) {
index = manager.getFieldWithFocusIndex();
}
return true;
}
}
well i set the extent of the bitmap field and placed the bitmap field in an horizontal field manager and it worked
in
class myscreen extends MainScreen
{
BitmapField mBitmapField;
hm = new HorizontalFieldManager();
hm.add(mBitmapField)
protected boolean navigationClick(int status, int time)
{
if (hm.getFieldWithFocusIndex==0)
{
Dialog.inform("Image focussed");
}
return true;
}
}
i dont understand why earlier same logic was not working!!!!!!!!!!
may be bcoz of extent of BitmapField
Try to override inline the bitmapField navigationClick and drawFocus method so you dont need to care about the index, when the user click to the bitmap then your code will run.
protected void drawFocus(Graphics graphics, boolean on){
//the simplies way to draw a rectangle and this will be the focus
}
protected boolean navigationClick(int status, int time)
{
//write here your code what you want to run the user clicks to the bitmap
return true;
}
精彩评论