从导航中调用navigationClick在Blackberry中点击“父亲”

时间:2015-08-13 13:04:22

标签: blackberry

编辑 ...

我正在尝试在BlackBerry应用中部署新组件。我有一个新的类扩展了Horizo​​ntalFieldManager,我在其中实例化了一个新的ListField。在其中,我覆盖了navigationClick方法并打开了一个弹出窗口。此组件的名称是CustomComponentHorizo​​ntal。我在自定义的其他组件中使用此组件,其名称为CustomComponentVertical。这是代码:

在Main.java中:

...

CustomComponentVertical ccv=new CustomComponentVertical();

...

add(ccv);

在CustomComponentVertical

...

CustomComponentHorizontal cch=new CustomComponentHorizontal{

...

    protected boolean navigationClick(int status, int time) {
        //Should I do something here??
        return super.navigationClick(status, time);
      }
  };

...

add(cch);

在CustomComponentHorizo​​ntal中:

 public class CustomComponentHorizontal extends HorizontalFieldManager {
      ListField choiceField=null;
      PopupScreen popup=null;
      public CustomComponentHorizontal (){
          choiceField = new ListField(){
          public boolean navigationClick(int status, int time) {
            Field focus = UiApplication.getUiApplication().getActiveScreen().getLeafFieldWithFocus();
            if (focus instanceof ListField) {
              popup = new ChoicePopupScreen(10, 50, choices);
                    popup.setChoice(choices);      
                    UiApplication.getUiApplication().pushScreen(popup);
                    setPopup(popup);
              return super.navigationClick(status, time);
            }
          };      
        }
      }
    }

我的目的是当我点击我的组件时,它会启动listClick的listClick。当我将焦点放在我的组件中并单击触控板时,弹出窗口没有打开。但是,如果我触摸屏幕上的组件,然后我点击触控板,弹出打开。 如何在不使用触摸事件的情况下从组件打开弹出窗口?

非常感谢。

1 个答案:

答案 0 :(得分:1)

我复制粘贴你的代码。有一些错误,您的回调丢失了。所以我修改了一下并创建了一个简单的回调来测试,并navigationClick点火。希望这有帮助,请告诉我是否有一个我不理解的不同问题。

public CustomComponent()
    {
        elements = new Vector();
        elements.addElement("Element 0");
        elements.addElement("Element 1");
        elements.addElement("Element 2");
        elements.addElement("Element 3");
        elements.addElement("Element 4");
        elements.addElement("Element 5");

        choiceField = new ListField(elements.size())
        {
            public boolean navigationClick(int status, int time)
            {
                int index = getSelectedIndex();
                Dialog.inform((String) elements.elementAt(index));

                return true;
            }
        };

        choiceField.setCallback(new ListFieldCallback()
        {
            public int indexOfList(ListField listField, String prefix, int start)
            {
                return elements.indexOf(prefix, start);
            }

            public int getPreferredWidth(ListField listField)
            {
                return Display.getWidth();
            }

            public Object get(ListField listField, int index)
            {
                return elements.elementAt(index);
            }

            public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width)
            {
                String obj = (String) get(listField, index);
                graphics.setColor(0x000000);
                graphics.drawText(obj, 0, y, 0, width);
            }
        });

        add(choiceField);
    }