How to create Code name one dynamic list using ui builder
-
21-12-2019 - |
Question
Can Any one post a sample dynamic list using U i builder in code name one without hard code. i want a list populated through dynamic data.?
protected boolean initListModelList(List cmp) {
cmp.setModel(new com.codename1.ui.list.DefaultListModel(new String[] {"Firstname", "LastName", "Email"}));
return true;
}
Solution
Following code populates CN1 Multilist dynamically from a Hashtable. Here usersList is a Hashtable. Write the code in the List Model event of the List.
Vector vec = new Vector();
Object[] keys = usersList.keySet().toArray();
for (int iter = 0; iter < keys.length; iter++) {
InputStream is = null;
Hashtable temp = new Hashtable();
temp.put("Line1", usersList.get(keys[iter]));
vec.addElement(temp);
}
cmp.setModel(new DefaultListModel(vec));
vec.clear();
Thanks!
OTHER TIPS
I don't understand the problem? Instead of using an array just pass a collection with your data or pretty much anything you want.
If you want to download data dynamically or something more elaborate just implement your own ListModel
to fetch data asynchronously e.g. https://code.google.com/p/codenameone/source/browse/trunk/CodenameOne/src/com/codename1/cloud/CloudListModel.java
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow