Parse Server querying a list then adding to a Container list

70 Views Asked by At

Finally my parse4cn1 API is working with Codename One! I'm glad it worked but I'm having issues to get a list from a query then add it to a Container list in order to be displayed on my App screen.

I use this Menu to add data in the Database:

public void addMenu() {

        final Form addMenu = new Form("Menu");
        addMenu.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        Button back = new Button("Back to Main Menu");

        ParseObject po = ParseObject.create("mytable");

        List<String> list = new ArrayList<String>();
        list.add("Book's Title: " + "Iron Maiden");
        list.add("Book description: " + "Heavy Metal");
        list.add("Author: " + "Bruce");
        list.add("Donor: " + "Unknown");
        list.add("Date of subscription: " + "29/03/2018");
        list.add("Book Status: " + "Available");

        po.put("codeID", list);

        try {

            po.save();

        } catch (com.parse4cn1.ParseException e) {

            Dialog.show("Err", "Something went wrong.", "OK", null);
        }

        addMenu.add(back);
        addMenu.show();    

        back.addActionListener(new ActionListener() 
        {
            public void actionPerformed(ActionEvent ev) 
            {
                new StateMachine("/theme");
            }
        });
    }

Then I use this Menu to query data back:

public void infoMenu() {

            final Form infoMenu = new Form("Book Info");
            infoMenu.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

            Container list = new Container();
            list.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
            list.removeAll();

            Button back = new Button("Back to Main Menu");

            ParseQuery<ParseObject> query = ParseQuery.getQuery("mytable");
            query.whereExists("codeID");

            List<ParseObject> results = null;

            try {

                results = query.find();
                //HOW TO ADD RESULTS TO THE CONTAINER LIST?

            } catch (com.parse4cn1.ParseException e) {

                Dialog.show("Err", "Something went wrong.", "OK", null);
            }

            infoMenu.add(list);
            infoMenu.add(back);
            infoMenu.show();

    back.addActionListener(new ActionListener() 
    {
        public void actionPerformed(ActionEvent ev) 
        {
            new StateMachine("/theme");
        }
    });
}

My question is how to add results to the Container list?

1

There are 1 best solutions below

0
On BEST ANSWER
if(!results.isEmpty()) {    
   int index = 0;       
   int size = results.size();
   for(;index < size;++index) {
   list.add(btn = new 
   MultiButton(results.get(index).getString("Title")));
   addListener(btn);
}