我想在新屏幕上获取所选列表行标题,但无论点击哪个列表行,我都只获得最后一个列表行标题。
以下是示例代码:
Bitmap listThumb = Bitmap.getBitmapResource("icon.png");// Dummy Icon
listTitle = "Headline"; // Dummy value
Bitmap navBar = Bitmap.getBitmapResource("icon.png");// Dummy Icon
Vector v = new Vector();
for (int i = 0; i <= 10; i++) {
listTitle = listTitle + i;
v.addElement(new ListRander(listThumb, listTitle, navBar));
myListView = new CustomListField(v) {
public boolean trackwheelClick(int status, int time) {
int index = getSelectedIndex();
// get selected index title ...
UiApplication.getUiApplication().pushScreen(
new InnerPage(listTitle));
return true;
}
};
}
add(myListView);
可以通过使用FieldChangeListener&amp;获得标题。怎么??
答案 0 :(得分:0)
此代码几乎与此问题相同:
Get selected index list title blackberry java
但问题可能有点不同。
首先,这里似乎存在逻辑错误。这看起来不对:
for (int i = 0; i <= 10; i++) {
listTitle = listTitle + i;
v.addElement(new ListRander(listThumb, listTitle, navBar));
myListView = new CustomListField(v) {
public boolean trackwheelClick(int status, int time) {
int index = getSelectedIndex();
// get selected index title ...
UiApplication.getUiApplication().pushScreen(
new InnerPage(listTitle));
return true;
}
};
}
不应该是:
for (int i = 0; i <= 10; i++) {
listTitle = listTitle + i;
v.addElement(new ListRander(listThumb, listTitle, navBar));
}
myListView = new CustomListField(v) {
public boolean trackwheelClick(int status, int time) {
int index = getSelectedIndex();
// get selected index title ...
UiApplication.getUiApplication().pushScreen(
new InnerPage(listTitle));
return true;
}
};
鉴于此,请使用navigationClick()替换trackwheelClick(),如引用的Thread中所示。
调试此行返回的索引:
int index = getSelectedIndex();
如果这始终是最后一个值,则问题出在CustomListField的getSelectedIndex()方法中,当然我们没有....
如果它是您期望的索引值,那么您可以在Vector v中引用相关元素。