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()
        {

             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

    }

}

如果您发现问题,这将是很大的帮助.. 谢谢。

4

2 回答 2

0

看看这个,这是 ListField 实现的一个很好的例子,因为我在 Mac 上,我无法运行你的代码。希望它可以帮助你。

于 2012-12-06T05:55:17.913 回答
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

}

}
于 2012-12-06T07:07:52.740 回答