Java me 如何在画布中创建多个复选框
当我试图在画布中创建复选框时,会遇到麻烦 我的复选框运行良好,但我不知道如何存储每个项目的值,这意味着当用户选中第1行,然后他们移动到另一行时,复选框仍然选中第1行,当用户选中第1行和第2行并移动到另一行时,复选框将选中第1行和第2行Java me 如何在画布中创建多个复选框,java-me,midp,lcdui,Java Me,Midp,Lcdui,当我试图在画布中创建复选框时,会遇到麻烦 我的复选框运行良好,但我不知道如何存储每个项目的值,这意味着当用户选中第1行,然后他们移动到另一行时,复选框仍然选中第1行,当用户选中第1行和第2行并移动到另一行时,复选框将选中第1行和第2行 但是我找不到这个问题的解决方案修改您的代码以使用selectTodelete作为布尔数组而不是int,如下所示 // ...initialization of DataList boolean[] selectTodelete = new bool
但是我找不到这个问题的解决方案修改您的代码以使用
selectTodelete
作为布尔数组而不是int,如下所示
// ...initialization of DataList
boolean[] selectTodelete = new boolean[2]; // instead of int
{ selectTodelete[0] = selectTodelete[1] = false; } // init array
Command editCommand, backCommand,selectCmd, unselectCmd,selectAll;
//...
protected void paint(Graphics g) {
//...
for(int i =0 ; i<countRow; i++ ){
//draw background
//...
if(selectTodelete[i]){ // was selectTodelete == 1
//draw select dot at location for row 'i'
//...
}
// remove: you don't need that anymore: if(selectTodelete == 2) {
//draw select dot...
//}
// draw a checkbox before each item
// ...
}
}
public void commandAction(Command c, Displayable d) {
//...
if(c == selectCmd){
selectTodelete[selectedItem] = true;
}
if(c== unselectCmd){
selectTodelete[selectedItem] = false;
}
if(c == selectAll){
selectTodelete[0] = selectTodelete[1] = true;
}
repaint();
}
//...
}
…当您需要它来处理RCID时,像这样公开的信息可以在任何地方进一步使用,例如在下面的方法中:
Vector useSelection(DataList dataList, DataStore[][] ds) {
Vector result = new Vector();
int count = ds.length;
for(int i = 0; i < count; i++ ) {
if (!dataList.isSelected(i)) {
continue; // skip non selected
}
System.out.println("RCID selected: [" + ds[i][5].cellText + "]");
result.addElement(ds[i][5]);
}
return result;
}
Vector useSelection(数据列表数据列表,数据存储[][]ds){
向量结果=新向量();
int count=ds.length;
for(int i=0;i
对不起,兄弟,我能再问你一个问题吗。在我的代码中,我想让RCID适合于选中它,这意味着当选中行时,我可以获得此id,当我使用delete命令时,它将删除选中的所有行。感谢You@MYE我更新了答案,展示了如何使用selectTodelete
来处理RCID非常感谢您,但我想知道,如何将它添加到数组中,因为我需要获取id才能删除项我想知道如何将J2Me中的向量转换为int数组,因为我需要获取int值才能删除resultset中的记录。在j2me中可以是vector().toArray,但在j2me中如何做到这一点?@MYE如果需要int值,则无需转换。要在索引i
处获取该值,只需使用vector elementAt方法:((整数)(vector.elementAt(i))).intValue()
Vector useSelection(DataList dataList, DataStore[][] ds) {
Vector result = new Vector();
int count = ds.length;
for(int i = 0; i < count; i++ ) {
if (!dataList.isSelected(i)) {
continue; // skip non selected
}
System.out.println("RCID selected: [" + ds[i][5].cellText + "]");
result.addElement(ds[i][5]);
}
return result;
}