任何人都可以建議我如何在黑莓中創建一個可單擊的列表字段,以便點擊一個項目時必須出現一個新的畫面。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已棄用
我嘗試了上面的例子,但是有許多事情我不能跟隨這麼多東西。任何人都可以用簡單的代碼來幫助我 –