如何使TextField在List中可编辑?

时间:2013-01-14 09:42:14

标签: lwuit lwuit-textfield lwuit-list

有一个包含TextFields的List。问题是这些字段不可编辑!这是代码:

    public formConstructor()
    {
       ...
       private Vector vList = new Vector(); // datasource of the list
       private CListCellProduits listRenderer;
       private List list;
       ...
       listRenderer          = new CListCellProduits(20);
       vList.addElement(new String("P001;"));
       vList.addElement(new String("P002;"));
       list             = (new ListUtil(vList)).createList(listRenderer);
       addComponent(list);
       ...
    }

    public class CListCellProduits extends Container implements ListCellRenderer {
        private Label focus = new Label("");
        private Label lData;
        private Champ sortie = new Champ("123", TextArea.NUMERIC);
        private Champ dispo = new Champ("123", TextArea.NUMERIC);
        private int widthCommun;
        private Container cRow1 = new Container(new BoxLayout(BoxLayout.X_AXIS));

        public CListCellProduits(int widthCommun)
        {
            super();
            setLayout(new BoxLayout(BoxLayout.Y_AXIS));

            lData = new Label("");

            sortie.setPreferredW(widthCommun);
            dispo.setPreferredW(widthCommun);
            this.widthCommun = widthCommun;

            cRow1.addComponent(lData);
            cRow1.addComponent(sortie);
            cRow1.addComponent(dispo);
            addComponent(cRow1);
        }
        public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
        {
            Content entry = null;
            if (value instanceof Content)
                entry = (Content)value;
            if (!"".equals(entry.getColumn(0)))
                lData.setText(entry.getColumn(0));
            else
                lData.setText("-");
            lData.setPreferredW(widthCommun);
            list.repaint();

            return this;
        }
        public Component getListFocusComponent(List arg0)
        {
            return focus;
        }
    }

    public class ListUtil {

        private Vector data = new Vector();
        private Content[] contents;

        public ListUtil(Vector vData)
        {
            data = vData;
            contents = new Content[vData.size()];
        }

        public List createList(CListCellProduits renderer)
        {
            CList theList;
            for(int i = 0; i < data.size(); i++)
            {
                contents[i] = new Content(String.valueOf(data.elementAt(i)));
            }
            theList = new CList(contents, renderer);
            return theList;
        }
    }

    public class CList extends List {
        public CList(Object[] data, CListCellProduits renderer)
        {
            super(data);
            setListCellRenderer(renderer);
            setScrollAnimationSpeed(getScrollAnimationSpeed()/4);
        }
    }

public class Champ extends TextField {

    public Champ(String imo)
    {
        super();
        setReplaceMenu(false);
        setInputModeOrder(new String[]{imo});
    }
    public Champ(String imo, int contrainte)
    {
        super();
        setReplaceMenu(false);
        setInputModeOrder(new String[]{imo});
        setConstraint(contrainte);
    }
    protected Command installCommands(Command clear, Command t9)
    {
        return null;
    }
}

在运行时它会提供如下内容:

enter image description here

那么如何使TextFields可编辑?

1 个答案:

答案 0 :(得分:1)

列表中的不可能

列表仅用于显示不适用于文本字段的可点击项目列表。