0
votes

Am facing some problem with populating the Multilist in Codename One. But values are not loaded in the form. It shows blank list with checkbox. What am I doing wrong ?

@Override
    protected boolean initListModelMultiList(List cmp) {
        Vector vec = new Vector();
        Hashtable h = new Hashtable();
        h.put("User1", "List1");
        h.put("User2", "List2");
        h.put("User3", "List3");
        vec.addElement(h);
            cmp.setModel(new DefaultListModel(vec));
        return true;
    }

Below warnings are displayed in the eclipse window. Vector vec = new Vector() is line number 279.

Description Resource Path Location Type Vector is a raw type. References to generic type Vector should be parameterized StateMachine.java /Testing/src/userclasses line 279 Java Problem List is a raw type. References to generic type List should be parameterized StateMachine.java /Testing/src/userclasses line 278 Java Problem Hashtable is a raw type. References to generic type Hashtable should be parameterized StateMachine.java /Testing/src/userclasses line 280 Java Problem Hashtable is a raw type. References to generic type Hashtable should be parameterized StateMachine.java /Testing/src/userclasses line 280 Java Problem Vector is a raw type. References to generic type Vector should be parameterized StateMachine.java /Testing/src/userclasses line 279 Java Problem

1

1 Answers

1
votes

You need 3 elements in the list not in the vector and the keys for the hashtable need to match the keys defined in the multi-list see http://www.codenameone.com/how-do-i---create-a-list-of-items-the-easy-way.html

Sample code:

Vector v = new Vector();
for(int iter = 0 ; iter < 100 ; iter++) {
   Hashtable h = new Hashtable();
   h.put("Line1", "First line of row: " + iter");
   h.put("Line2", "Second line of row: " + iter");
   v.addElement(h);
}
cmp.setModel(new DefaultListModel(v));