java - Codename 一台用于检索列表的解析服务器

标签 java list codenameone parse-server parse4cn1

您好,我正在使用 Codename One 和 Parse Server 将数据库保存在我的移动应用程序中,但我想将查询的每个结果放在一个按钮中,因为我需要单击列表中的每个元素。 ParseQuery.getQuery("List") "List"是数据库中引用的 ID,"Title"返回 String。

//Method:

public Container retrieveList(String content) {

    Container list = new Container(BoxLayout.y());

    ParseObject po = null;

    try {

        po = ParseObject.fetch(content /*class name*/, "nsC2NdmCuQ" /*objectId*/);

    } catch (ParseException e) {

        Dialog.show("Err", "Oops! Database is not available at the moment" + e.getCode(), "OK", null);
    }

    Label title = new Label("Book's Title: " + po.getString("Title"));
    list.addComponent(title);
    return list;
}

//MENU: 

public void listMenu() {

final Form listMenu = new Form("Welcome to the List Menu"); listMenu.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); ParseQuery<ParseObject> query = ParseQuery.getQuery("List"); query.whereExists("Title"); List<ParseObject> results = null; Container dumpList = null; listMenu.add(dumpList).removeAll(); ParseServerDAO ps = new ParseServerDAO(); try { results = query.find(); int index = 0; for(;index < results.size();) { dumpList = ps.retrieveList(//How to get each element from results?); //Add each element of results to a button. } } catch (com.parse4cn1.ParseException e) { Dialog.show("Oops! Try later, server is not working right now.", "", "OK", null); } listMenu.add(dumpList); }

最佳答案

如果你想要一个按钮列表,你可能应该这样做:

public MultiButton retrieveListItem(String content, ActionListener l) {
    ParseObject po = null;
    try {

        po = ParseObject.fetch(content /*class name*/, "nsC2NdmCuQ" /*objectId*/);

    } catch (ParseException e) {

        Dialog.show("Err", "Oops! Database is not available at the moment" + e.getCode(), "OK", null);
    }

    MultiButton title = new MultiButton("Book's Title: " + po.getString("Title"));
    title.addActionListener(l);
    title.putClientProperty("ParseObject", po);
    return title;
}

请注意,您可以使用 Button , MultiButton , SpanButton等用于各种用例。

请注意,在操作监听器中,您需要调用 getActualComponent()在事件对象上, getComponent() .

例如事件处理代码:

 public void actionPerformed(ActionEvent ev) {
     MultiButton mb = ev.getActualComponent();
     ParseObject po = (ParseObject)mb.getClientProperty("ParseObject");
 }

关于java - Codename 一台用于检索列表的解析服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49522067/

相关文章:

python - 组合 3 个列表以创建字典列表

codenameone - 黑屏在启动android应用程序时闪烁

java - getServingUrl() 方法使用谷歌云存储值

java - MigLayout在java中无法解析

python - 如何根据开始和结束元素从列表创建子列表?

java - 如何使用java查找并列出selenium中ul li标签下的元素和ul li位于div下的元素?

java - 如何动态更改工具栏命令文本

java - Codename.one 生成的 apk 文件的源代码

java - 使用Java在Hadoop中形成自定义链接列表

java - apache 守护程序 procrun- java 应用程序作为 windows 服务- 无法在 64 位 windows 7 中启动