我想在弹出屏幕中输入一个列表字段。列表正在顺利进行。但是,当我点击列表中的特定行时,它不会触发任何事件。发出一个对话框。但它也没有用。这是我的代码:
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
}
}
如果您发现问题,将会有很大的帮助.. 感谢。
答案 0 :(得分:0)
看看this,这是ListField实现的一个很好的例子,因为我在Mac上,我无法运行你的代码。希望它可以帮助你。
答案 1 :(得分:0)
最后我能解决这个问题。我正在为列表视图编写导航单击。现在它正常运作..
这是我更新的代码:
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();
_listField.setCallback(_callback);
initializeList();
add(_listField);
}
protected boolean navigationClick(int arg0, int arg1) {
// TODO Auto-generated method stub
int index = _listField.getSelectedIndex();
if(index == 0)
{
UiApplication.getUiApplication().popScreen(this);
Logger.out("AttachmnentList", "first row clicked");
Dialog.alert("Grocery Clicked");
}
else if(index == 1)
{
Dialog.alert("To Do's Clicked");
}
return super.navigationClick(arg0, arg1);
}
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
}
}