user1983864
user1983864

Reputation: 7

Invoking navigationClick from navigationClick 'father' in Blackberry

Edited ...

I´m trying to deploy a new component in my BlackBerry app. I have a new class that extends of HorizontalFieldManager, where I instanced a new ListField. Inside of this, I overwrote the navigationClick method and I open a popup. The name of this component is CustomComponentHorizontal. I use this component in other component customized, its name is CustomComponentVertical. This is the code:

In Main.java:

...

CustomComponentVertical ccv=new CustomComponentVertical();

...

add(ccv);

In CustomComponentVertical

...

CustomComponentHorizontal cch=new CustomComponentHorizontal{

...

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

...

add(cch);

In CustomComponentHorizontal:

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

My purpose is that when I click in my component, it is launched the navigationClick of listfield. When I put the focus in my component and click with trackpad, the popup no open. But, If I touch the screen over the component, and then I click with trackpad, popup open. How could I open the popup from component without to use the touch event?

Thank you very much.

Upvotes: 0

Views: 46

Answers (1)

Kevin
Kevin

Reputation: 1628

I copy pasted your code. There were some errors, and your callback was missing. So I fixed it up a bit and created a simple callback to test with, and the navigationClick fires. Hopefully this helps, let me know if there is a different issue I didn't understand.

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

Upvotes: 1

Related Questions