user3517929
user3517929

Reputation: 235

Ecommerce App in CodenameOne

Hi I am a newbie in CodenameOne am now creating a eCommerce app using CodenameOne resource editor ,I have used multilist for displaying products . I have checked the checkbox feature wherein I got the checkbox for all my items .My question here is by code in statemachine how do I get the name of product checked by the user and how to get whether the checkbox is checked or not .I tried implementing findMultiList().getSelected() but it returns always true if I check r uncheck.

Please help me also it would be great if you could tell me how to integrate google drive in my project because I need to pull data from excel sheet and populate it in the list.

Upvotes: 3

Views: 222

Answers (2)

CookieJar
CookieJar

Reputation: 1

Codename One doesn't have dedicated support for google drive api yet... However, it does support Firebase (noSQL, so no table type data) THis means you'll have to work with variable pairs. There are resources for table databases, though : https://www.codenameone.com/javadoc/com/codename1/db/Database.html

check out these libraries https://github.com/shannah/cn1-data-access-lib (Accessing data from web, sqlite support)

https://github.com/jegesh/cn1-object-cacher (cache from web db)

These resources should help; good luck with your development :)

Upvotes: 0

Shai Almog
Shai Almog

Reputation: 52760

You need to get the model and traverse the elements within it:

ListModel<Map<String, Object>> model = (ListModel<Map<String, Object>>)findMultiList(c).getModel();
ArrayList<Map<String, Object>> items = new ArrayList<>();
for(int iter = 0 ; iter < model.getSize() ; iter++) {
   Map<String, Object> current = model.getItemAt(iter);
   String checked = (String)current.get("emblem");
   if(checked != null && "true".equals(checked)) {
       items.add(current);
   }
}

I haven't tried this code but it should work. Notice that the name "emblem" is the default name used for the MultiButton/MultiList but you can change it to be anything.

You can place a break point on the for loop and inspect the map elements as you traverse them to see how this works.

Upvotes: 2

Related Questions