【问题标题】:J2ME , Quizz using choiceGroupsJ2ME , 使用选择组的测验
【发布时间】:2015-04-27 01:53:09
【问题描述】:

我正在 j2Me 上做一个驾驶执照项目,其中包括像测验这样的测试,嗯,我在解析问题并将它们移动到 choiceGroups 之后遇到了问题:

if (questions.length > 0) {
  for (int i = 0; i < questions.length; i++) {

    ChoiceGroup reponses = new ChoiceGroup("Reponses" + i, Choice.EXCLUSIVE);
    reponses.append(questions[i].getReponse1(), null);
    reponses.append(questions[i].getReponse2(), null);
    reponses.append(questions[i].getReponse3(), null);
    pass.append(questions[i].getContenu());
    pass.append(reponses);

  }
}

} catch (Exception e) {
  System.out.println("Exception:" + e.toString());
}
disp.setCurrent(pass);

下一步是控制choiceGroups 的命令来测试它们是否像真正的答案。 所以我在这里被屏蔽了。

  if (c == valider) {
    int result = 0;
    for (int i = 0; i < pass.size(); i++) {

      String ch = pass.get(i).getLabel();
      System.out.println(ch);

    }

  }

我不知道如何从选择组中获得选择 任何帮助

【问题讨论】:

  • 什么是 ChoiceGroup?为所有这些发布一些代码。
  • ChoiceGroup 响应 = new ChoiceGroup("Reponses" + i, Choice.EXCLUSIVE); CHoice.Exclusive 就像 Html 中的 radioBox

标签: java xml-parsing java-me


【解决方案1】:

实际上,我不确定你到底想要什么:

此代码将帮助您从我很久以前所做的选择组中获取选定的项目:

//get a selected array in choicegroup
    private String[] choiceGroupSelected(ChoiceGroup cg) {
        String selectedArray[] = new String[cg.size()];
        int k = 0;
        for (int i = 0; i < cg.size(); i++) {
            if (cg.isSelected(i)) {
                selectedArray[k] = cg.getString(i);
                k++;
            }
        }
        return selectedArray;
    }

该功能将帮助我获取所有选定的项目以进行以下删除操作:

private void deleteSpecificItem() {
        try {
            String temp = null;
            int index;
            //get ChoiceGroup size
            int numbers = cgTrip.size();
            String selectedItems[] = choiceGroupSelected(cgTrip);
            //
            rs = services.RecordStoreManager.openRecordStoreByName("TripRS");
            re = rs.enumerateRecords(null, null, true);
            String[] tripList = new String[2];
            for (int i = 0; i < numbers; i++) {
                temp = selectedItems[i];
                if (temp != null) {
                    while (re.hasNextElement()) {
                        try {
                            index = re.nextRecordId();
                            System.out.println("RecordID: " + index);
                            byte[] byteBuff = rs.getRecord(index);
                            String source = new String(byteBuff);
                            tripList = services.StringManager.getItems(source, ";", 2);
                            String strProcess = tripList[0] + "-" + tripList[1];
                            //inspect all of items in choicegroup and if they are selecting then compare with record
                            //If comparison is true then delete this record
                            if (temp.equals(strProcess)) {
                                System.out.println("Delete RecordID: " + index);
                                rs.deleteRecord(index);
                                re.keepUpdated(true);
                                break;
                            }
                        } catch (RecordStoreException ex) {
                            ex.printStackTrace();
                        }
                    }
                }
            }
            try {
                rs.closeRecordStore();
            } catch (RecordStoreException ex) {
                ex.printStackTrace();
            }
            rs = null;
            re.destroy();
            this.LoadTripItem();
        } catch (RecordStoreNotOpenException ex) {
            ex.printStackTrace();
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 2016-02-06
    • 2016-07-09
    相关资源
    最近更新 更多