Last active
July 8, 2020 09:57
-
-
Save codenameone/b2ab6645db842d7b2750 to your computer and use it in GitHub Desktop.
Sample for creating a simple MultiList UI in Codename One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void showForm() { | |
Form hi = new Form("MultiList", new BorderLayout()); | |
int mm = Display.getInstance().convertToPixels(3); | |
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(mm * 3, mm * 4, 0), false); | |
Image icon1 = URLImage.createToStorage(placeholder, "icon1", "http://www.georgerrmartin.com/wp-content/uploads/2013/03/GOTMTI2.jpg"); | |
Image icon2 = URLImage.createToStorage(placeholder, "icon2", "http://www.georgerrmartin.com/wp-content/uploads/2012/08/clashofkings.jpg"); | |
Image icon3 = URLImage.createToStorage(placeholder, "icon3", "http://www.georgerrmartin.com/wp-content/uploads/2013/03/stormswordsMTI.jpg"); | |
Image icon4 = URLImage.createToStorage(placeholder, "icon4", "http://www.georgerrmartin.com/wp-content/uploads/2012/08/feastforcrows.jpg"); | |
Image icon5 = URLImage.createToStorage(placeholder, "icon5", "http://georgerrmartin.com/gallery/art/dragons05.jpg"); | |
ArrayList<Map<String, Object>> data = new ArrayList<>(); | |
data.add(createListEntry("A Game of Thrones", "1996", icon1)); | |
data.add(createListEntry("A Clash Of Kings", "1998", icon2)); | |
data.add(createListEntry("A Storm Of Swords", "2000", icon3)); | |
data.add(createListEntry("A Feast For Crows", "2005", icon4)); | |
data.add(createListEntry("A Dance With Dragons", "2011", icon5)); | |
data.add(createListEntry("The Winds of Winter", "2016 (please, please, please)", placeholder)); | |
data.add(createListEntry("A Dream of Spring", "Ugh", placeholder)); | |
DefaultListModel<Map<String, Object>> model = new DefaultListModel<>(data); | |
MultiList ml = new MultiList(model); | |
hi.add(BorderLayout.CENTER, ml); | |
hi.show(); | |
} | |
private Map<String, Object> createListEntry(String name, String date, Image icon) { | |
Map<String, Object> entry = new HashMap<>(); | |
entry.put("Line1", name); | |
entry.put("Line2", date); | |
entry.put("icon", icon); | |
return entry; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage code for MultiList & DefaultListModel.
From the Codename One project