Java J2ME,使用ChoiceGroup的测验
我正在j2Me wich上做一个驾驶执照项目,包括测验之类的测试,我在分析问题并将其放入选择组后遇到了问题,就像这样:Java J2ME,使用ChoiceGroup的测验,java,xml-parsing,java-me,Java,Xml Parsing,Java Me,我正在j2Me wich上做一个驾驶执照项目,包括测验之类的测试,我在分析问题并将其放入选择组后遇到了问题,就像这样: if(questions.length>0){ for(int i=0;i
if(questions.length>0){
for(int i=0;i ChoiceGroup Responses=新的ChoiceGroup(“Responses”+i,Choice.EXCLUSIVE);
append(问题[i].getReponse1(),null);
append(问题[i].getReponse2(),null);
append(问题[i].getReponse3(),null);
append(问题[i].getContenu());
通过。追加(回复);
}
}
}捕获(例外e){
System.out.println(“异常:+e.toString());
}
显示设置电流(通过)代码>事实上,我不确定你到底想要什么:
此代码将帮助您从choicegroup中获取我很久以前做过的选定项目:
//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;
}
//在choicegroup中获取所选数组
私有字符串[]choiceGroupSelected(ChoiceGroup cg){
字符串selectedArray[]=新字符串[cg.size()];
int k=0;
对于(int i=0;i
该功能将帮助我获取所有选定的项目以执行以下删除操作:
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();
}
}
private void deleteSpecificItem(){
试一试{
字符串temp=null;
整数指数;
//获取ChoiceGroup大小
int numbers=cgTrip.size();
字符串selectedItems[]=choiceGroupSelected(cgTrip);
//
rs=services.RecordStoreManager.openRecordStoreByName(“TripRS”);
re=rs.records(null,null,true);
字符串[]三元组=新字符串[2];
对于(int i=0;i
什么是ChoiceGroup?为所有这些发布一些代码。ChoiceGroup reponses=新的ChoiceGroup(“reponses”+i,Choice.EXCLUSIVE);选择。独占就像Html中的radioBox