2

我正在尝试使用FieldManagers(水平和垂直)创建列表。在这个列表中,我有多个可点击的项目,比如按钮,所以我没有使用ListFieldObjectListField如何在BlackBerry中附加并获取特定列表项ID?

我已成功创建用户界面,但我无法附加来自服务器的特定项目标识。另外,单击任何列表行中的某个特定按钮时,我想获取该项目标识并希望对该标识执行操作。

因此,请让我知道如何在我使用FieldManager时将id附加到特定行,然后如何在点击按钮时针对该ID生成事件?

+0

我们应该看看你试过了吗? – Signare 2013-05-09 09:10:21

回答

2

当您创建一行时,您可能正在为每行创建一个(的子类)Manager

至少,你似乎在每行创建一个ButtonField

您可以做的是在创建时为每行或每个按钮添加一个Cookie。 A cookie只是附加到对象的额外信息。然后,当单击该行或按钮时,您可以向行/按钮查询cookie,并使用该行标识行ID。

每个BlackBerry Field都可以附加一个cookie。由于Cookie的类型为Object,因此您可以制作任何您想要的东西。

例如,为您创造行的按钮后:

for (int i = 0; i < numRows; i++) { 
    BitmapButtonField button = new BitmapButtonField(onImage, offImage, ButtonField.CONSUME_CLICK); 
    // use the row index as the cookie 
    button.setCookie(new Integer(i)); 
    button.setChangeListener(this); 
    Manager row = new MyRowManager(); 
    row.add(button); 
    add(row); 
} 

,然后单击按钮时:

void fieldChanged(Field field, int context) { 
    Object cookie = field.getCookie(); 
    if (cookie instanceof Integer) { 
     Integer rowId = (Integer)cookie; 
     System.out.println("Row Id = " + rowId); 
    } 
} 

注:我使用的是黑莓高级UI BitmapButtonField为此,但Cookie技术将与任何FieldManager类一起使用。 See another example here

+0

:谢谢Nate ..我确实需要它,它为我工作。 – 2013-05-19 07:10:00

相关问题