在 Blackberry 上使用 navigationclick 与列表字段关联
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,以便在单击轨迹球时它可以继续运行不同的功能?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该重写类的 navigationClick 方法,而不是 VerticalFieldManager 的方法。意味着,您可以像构造函数一样将此方法编写为类的方法之一。
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.