最后我的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");
}
});
}
我的问题是如何将结果添加到容器列表中?
答案 0 :(得分: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);
}