我正在尝试在弹出屏幕中放置一个列表字段。清单来得正是时候。但是当我单击列表的特定行时,它不会触发任何事件。尝试显示一个对话框。但它也不起作用。这是我的代码:
public class AttachmentListPopup extends PopupScreen implements FieldChangeListener{
private ListField _listField;
private Vector _listElements;
public AttachmentListPopup()
{
super(new VerticalFieldManager());
_listElements = new Vector();
_listField = new ListField();
ListCallback _callback = new ListCallback()
{
public boolean navigationClick(int status, int time)
{
int index = _listField.getSelectedIndex();
if(index == 0)
{
Dialog.alert("Grocery Clicked");
}
else if(index == 1)
{
Dialog.alert("To Do's Clicked");
}
return true;
}
};
_listField.setCallback(_callback);
initializeList();
add(_listField);
}
private void initializeList()
{
String itemOne = "Grocery";
String itemTwo = "To Do's";
_listElements.addElement(itemOne);
_listElements.addElement(itemTwo);
_listField.setSize(_listElements.size());
_listField.setRowHeight(Display.getHeight()/6);
}
private class ListCallback implements ListFieldCallback
{
public void drawListRow(ListField list, Graphics g, int index, int y, int w)
{
y = y +20;
String text = (String)_listElements.elementAt(index);
g.drawText(text, (Display.getWidth() - getFont().getAdvance(text))/2, y, 0 , w);
}
public Object get(ListField list, int index)
{
return _listElements.elementAt(index);
}
public int indexOfList(ListField list, String prefix, int string)
{
return _listElements.indexOf(prefix, string);
}
public int getPreferredWidth(ListField list)
{
return Display.getWidth();
}
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
}
}
如果您发现问题,这将是很大的帮助.. 谢谢。