任何人都可以建议我如何在黑莓中创建一个可单击的列表字段,以便点击一个项目时必须出现一个新的画面。BlackBerry listfield development
1
A
回答
1
我在JDE 5.0上用VerticalFieldManager和自定义扩展字段做了类似的工作。
我假设你有一个你想在主屏幕上显示的对象列表。
首先;创建一个为您的列表项目扩展Field的类,根据您的要求重写其绘制方法,布局方法和其他事件。
接下来,创建一个您想要显示列表的主屏幕。一旦你填充了你的对象列表,在一个循环中,将每个对象模型传递给先前创建的字段的构造函数。然后将fieldChanged事件添加到该字段并将其添加到verticalFieldManager。
您需要重写事件(如fieldChanged事件),因为您想单击它并在另一个屏幕上显示其细节。
最后,创建一个详细信息屏幕,其中显示您的列表项目的对象详细信息所需的参数。在主屏幕实现的fieldChanged事件中,将对象传递给详细信息屏幕并推送详细信息屏幕。
另外,this方法可能对您有用。
实施例:
自定义字段:
public class CListItemField extends Field {
private CListItemModel model;
public CListItemField(CListItemModel _model, long style) {
super(style);
this.model = _model;
}
public CListItemModel getModel() {
return this.model;
}
// overrides
public int getPreferredHeight() {
//return custom height
}
public int getPreferredWidth() {
//return custom width
}
protected void layout(int width, int height) {
setExtent(Math.min(width, getPreferredWidth()), getPreferredHeight());
}
protected void paint(Graphics g) {
//custom paint stuff (borders, fontstyle, text position, icons etc.)
if (isFocus()) {
//focused item display settings
} else {
//item display settings
}
}
protected void drawFocus(Graphics graphics, boolean on) {
}
public boolean isFocusable() {
return true;
}
protected void onFocus(int direction) {
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
invalidate();
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean keyChar(char character, int status, int time) {
//send key event to listener
if (character == Keypad.KEY_ENTER) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
}
列表屏幕:
public class ScreenListbox extends MainScreen implements FieldChangeListener, FocusChangeListener {
private VerticalFieldManager verticalField;
private Vector listItemVector;
public ScreenOttoInbox(String title) {
super(title, Manager.NO_VERTICAL_SCROLL);
setData();
setComponents();
}
private void setData() {
//populate listItemVector according to your business (ie. read json response then parse it and collect it to a vector)
}
public void setComponents() {
verticalField = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
setListContent(verticalField, listItemVector);
add(verticalField);
}
private void setListContent(VerticalFieldManager field, Vector vector) {
try {
int vlen = vector.size();
for (int i = 0; i < vlen; i++) {
CListItemModel model = (CListItemModel) vector.elementAt(i);
CListItemField itemField = new CListItemField(model, Field.FOCUSABLE | Field.ACTION_INVOKE);
itemField.setChangeListener(this);
itemField.setFocusListener(this);
field.add(itemField);
}
} catch (Exception ex) { }
}
protected boolean onSavePrompt() {
return true;
}
public void fieldChanged(Field field, int context) {
//custom field's click/touch event handler
CListItemField itemField = (CListItemField) field;
ScreenItemDetail scrDetail = new ScreenItemDetail(itemField.getModel());
ScreenUtil.pushScreenWithLoader(scrDetail,true);
}
protected void onDisplay() {
super.onDisplay();
}
}
1
创建一个类像的下方。
import java.util.Vector;
import net.rim.device.api.collection.util.SparseList;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
public class CListCallback implements ListFieldCallback {
private String[] resource;
private int rgb=Color.BLACK;
Vector elements;
Bitmap arraow;
public CListCallback(String[] resources){
this.resource=resources;
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
String text=(String) get(listField, index);
graphics.setColor(rgb);
graphics.drawText(text,60,y+25);
graphics.drawLine(0, y+59, DConfig.disWidth, y+59);
}
public Object get(ListField listField, int index) {
return resource[index];
}
public int getPreferredWidth(ListField listField) {
return DConfig.disWidth+10;
}
public int indexOfList(ListField listField, String prefix, int start) {
return -1;
}
}
并在MainScreen类中使用上面的类。
CListCallback clmenu=new CListCallback(arrayitems);
final ListField lf = new ListField(arraymenu.length) {
protected boolean keyChar(char character, int status, int time) {
if (character == Keypad.KEY_ENTER) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
protected boolean navigationUnclick(int status, int time) {
fieldChangeNotify(0);
return true;
}
};
lf.setCallback(clmenu);
lf.setRowHeight(60);
lf.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{
int index=lf.getSelectedIndex();
UiApplication.getUiApplication.pushScreen(newNewScreen(imgarray[index]));
}
});
add(lf);
那it.it将工作
相关问题
- 1. BlackBerry 10 development- TextField
- 2. Blackberry Development&Maven2
- 3. 关于Blackberry中的ListField
- 4. BlackBerry动态更新ListField
- 5. 将标签添加到BlackBerry ListField
- 6. 如何检查blackberry listfield中的onchildclick?
- 7. 在BlackBerry ListField中绘制边框
- 8. 如何在BlackBerry中自定义ListField?
- 9. 在BlackBerry的ListField中显示EditField
- 10. Blackberry 6:ListField - 限制显示行数?
- 11. BlackBerry - 如何将clickEvent(setChangeListener)添加到BlackBerry中的ListField?
- 12. Blackberry Development,以编程方式在多人游戏中沟通两个Blackberry设备
- 13. 黑莓listfield
- 14. Blackberry:检测长按ListField并显示菜单
- 15. 带有来自URL(XML数据)的图像的Blackberry-ListField
- 16. Blackberry - 使用ListField自动更新新闻内容
- 17. BlackBerry Tree在TreeField或ListField中水平滚动
- 18. Blackberry-如何在每行上方制作ListField标题
- 19. BlackBerry ListField - 如何打开选定的列表项
- 20. Blackberry - ListField与来自文件系统的图像
- 21. BlackBerry上的ListField行中的文字环绕
- 22. Blackberry:我的ListField实现有什么问题?
- 23. 在BlackBerry中创建带有图像的ListField
- 24. Blackberry - 按日期对ListField数据进行排序
- 25. 如何为Blackberry中的ListField设置字段更改侦听器?
- 26. Onenote development
- 27. 黑莓的Listfield焦点问题
- 28. Blackberry - 如何在带有复选框的ListField中进行文本换行?
- 29. 如何创建自定义listField?
- 30. BlackBerry - ListFieldCallback已弃用
我尝试了上面的例子,但是有许多事情我不能跟随这么多东西。任何人都可以用简单的代码来帮助我 –