Using navigationclick in association with a listfield on Blackberry

894 views Asked by At
public class CategoriesUI extends MainScreen implements ListFieldCallback {
//categoryimport.listingnodup is the current categories with no duplicates
public Categories categoryimport = new Categories (); //brings in all infromation from     Categories.java
BitmapField bitmapField;
Bitmap nextselection = Bitmap.getBitmapResource("nextselection.png");
HorizontalFieldManager _hfm;
VerticalFieldManager _vfm;


private ListField allcategories;

CategoriesUI() {
try {
    FontFamily alphaSansFamily = FontFamily.forName("BBClarity");
    Font appFont = alphaSansFamily.getFont(Font.PLAIN, 12, Ui.UNITS_pt);
    setFont(appFont);
    } catch (ClassNotFoundException e) {
}



allcategories = new ListField(categoryimport.listingnodup.size());
allcategories.setCallback(this); //we manage the interaction!


//Get the device wudth and height
final int width = Display.getWidth();  
final int height = Display.getHeight();

//Draw background gradient on this manager and add VerticalfieldManager for scrolling

_hfm = new HorizontalFieldManager() {

//Sublayout is passed the width and height of the partent window and will tell the     window manager
//how to layout hte buttons, images, etc.
protected void sublayout(int w, int h) {

    //GetFieldCount returns the number of fields attached to the instance of this manger.
    //and lays out the postition
    if (getFieldCount() > 0){
        Field searchRes = getField(0);
        layoutChild(searchRes, width, height);
        setPositionChild(searchRes, 0, 0);
    }

    setExtent(width, height);
}
};
_vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.USE_ALL_HEIGHT|Manager.USE_ALL_WIDTH) {

protected boolean nagivationClick(int status, int time) {
    categoryimport.sections();
    nextscreen();
    return true;
}

public void paint (Graphics g) {
    //Variables for drawing the gradient
    int[] X_PTS_MAIN = { 0, width, width, 0 };
    int[] Y_PTS_MAIN = { 0, 0, height, height };
    int[] drawColor_MAIN = { Color.GRAY, Color.GRAY, Color.DARKGRAY, Color.DARKGRAY};

    try {
        //Draw the gradients
        g.drawShadedFilledPath(X_PTS_MAIN, Y_PTS_MAIN, null, drawColor_MAIN, null);

    } catch (IllegalArgumentException iae) {
        System.out.println("Bad Arguments.");
    }
    super.paint(g);
}
};
_vfm.add(new LabelField("List of Categories"));
_vfm.add(allcategories);
_hfm.add(_vfm);
add(_hfm);
}

//Get screen width and image width to move the image to the far right
int screenwidth = Display.getWidth();
int imagewidth = nextselection.getWidth();
int pushimagetoright = screenwidth - imagewidth;

//Returns the object at the specified index
public Object get(ListField list, int index)
{
    return categoryimport.listingnodup.elementAt(index);
}

//Implemented Call Back Methods follow
//draw the current row
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
    Object catdrawer = get(list, index);
    g.setColor(Color.BLACK);
    if(g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) {
        g.setGlobalAlpha(255);     
        g.drawBitmap(pushimagetoright, y, nextselection.getWidth(), nextselection.getHeight(), nextselection, 0, 0);
        invalidate();
        } else {
            g.setGlobalAlpha(50);
            g.drawBitmap(pushimagetoright, y, nextselection.getWidth(), nextselection.getHeight(), nextselection, 0, 0);
        }
    if(catdrawer != null) {       
        String drawer = catdrawer.toString();
        if (drawer != null) {
            g.drawText(drawer, 0, y, 0, w);
        }
    } 
}

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

public int indexOfList(ListField listField, String prefix, int start) {
    return start;
}

public void nextscreen() {
    int catnum = allcategories.getSelectedIndex();
    Object button = categoryimport.listingnodup.elementAt(catnum);
    categoryimport.categorysecondlvl = button.toString();
    if (categoryimport.namelisting.capacity() != 0) {
        categoryimport.namelisting.removeAllElements();
        }
    Categoriessndlvl categorysecondlvl = new Categoriessndlvl();
    UiApplication.getUiApplication().pushScreen(categorysecondlvl);   
}
}

The NavigationClick is not invokes when I run the simulator 8800-JDE on JDE 4.2.1 I believe it needs to be placed in a FieldManager and that is what I believe I have done. Thus my question is how to I invoke the navigationclick so when the trackball is clicked it can continue running a different function?

1

There are 1 answers

0
krishna On

I think you should override navigationClick method for class, not for VerticalFieldManager. Means, you can write this method like constructor as one of the methods of class.