0

在我的屏幕上有 3 个管理器 h1 h2 bmpf = new BitmapField

按这样的顺序添加

backgroundmanager.add(h1)
backgroundmanager.add(bmpf)
backgroundmanager.add(h2)

add(background manager);

protected boolesn navigationClick()
{
int index1 = h1.getFieldWithFocusIndex();
int index2 = h2.getFieldWithFocusIndex();
return true;
}

我得到了经理 h1 和 h2 中所有可聚焦字段的焦点索引

但是我无法获得焦点上的bitnmapfield的索引我需要在点击时执行一些代码

该怎么办

4

3 回答 3

1

你需要什么 BitmapField 索引?也许将 BitmapField 声明为屏幕成员会更容易?如果您仍然需要索引,请从字段中调用getIndex() 。

class Scr extends MainScreen {
    BitmapField mBitmapField;

    protected boolean navigationClick(int status, int time) {
        int bmpIndex = mBitmapField.getManager.getFocusedIndex();
        return true;
    }
}

更新Field 类中其他有用的方法是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;
    }
}
于 2010-03-10T12:30:35.920 回答
0

好吧,我设置了位图字段的范围并将位图字段放置在水平字段管理器中,它可以工作

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;
    }
}

我不明白为什么之前的相同逻辑不起作用!!!!!!!!!!

可能是 BitmapField 范围的 bcoz

于 2010-03-12T10:07:17.230 回答
0

尝试覆盖内联位图字段 navigationClick 和 drawFocus 方法,这样您就不需要关心索引,当用户单击位图时,您的代码将运行。


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; }

于 2010-03-12T14:14:22.787 回答