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

当我在 JDE 4.2.1 上运行模拟器 8800-JDE 时,未调用 NavigationClick 我相信它需要放置在 FieldManager 中,这就是我相信我所做的。因此我的问题是如何调用navigationclick,以便在单击轨迹球时它可以继续运行不同的功能?

4

1 回答 1

0

我认为您应该覆盖类的 navigationClick 方法,而不是 VerticalFieldManager。意味着,您可以像构造函数一样编写此方法作为类的方法之一。

于 2011-08-02T11:29:59.730 回答