1

最后,我的 parse4cn1 API 正在使用 Codename One!我很高兴它起作用了,但是我在从查询中获取列表然后将其添加到容器列表以显示在我的应用程序屏幕上时遇到问题。

我使用此菜单在数据库中添加数据:

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");
            }
        });
    }

然后我使用这个菜单来查询数据:

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");
        }
    });
}

我的问题是如何将结果添加到容器列表中?

4

1 回答 1

0
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);
}
于 2018-04-14T11:52:22.273 回答