ystem.out.println(this.currentSelectedObject.Ifselected());
this.itemList.removeElementAt(indexInItemList);
this.currentSelectedObject.setIfselected(true);
this.itemList.insertElementAt(currentSelectedObject,indexInItemList);
this.delete(this.currentSelectedIndex);
this.insert(this.currentSelectedIndex,
this.currentSelectedObject.getLabel(), icon);
} else {
Image icon = Util.getImage(this.currentSelectedObject.getImagePath());
this.itemList.removeElementAt(indexInItemList);
this.currentSelectedObject.setIfselected(false);
this.itemList.insertElementAt(currentSelectedObject,indexInItemList);
this.delete(this.currentSelectedIndex);
this.insert(this.currentSelectedIndex,
this.currentSelectedObject.getLabel(), icon);
}
this.setSelectedIndex(this.currentSelectedIndex,true);
}
}
}
}
}
附测试代码
| import java.util.Vector; import javax.microedition.lcdui.Choice; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; import com.skystudio.Canvas.ListCanvas; import com.skystudio.ExpandList.ExpandList; import com.skystudio.ExpandList.ExpandListItem; public class Main extends MIDlet { Display d=null; protected void startApp() throws MIDletStateChangeException { d=Display.getDisplay(this); ListTest(); } private void TestUI(){ ListCanvas l=new ListCanvas(); d.setCurrent(l); } private void ListTest(){ Vector v1=new Vector(); for(int i=0;i<10;i++){ v1.addElement(new ExpandListItem("土匪"+Integer.toString(i),"/img/default.png","/img/Group-open.png","土匪"+Integer.toString(i),ExpandListItem.ITEM,false)); } String v2="警察"; Vector v3=new Vector(); for(int i=0;i<10;i++){ v3.addElement(new ExpandListItem("警察"+Integer.toString(i),"/img/default.png","/img/Group-open.png","警察"+Integer.toString(i),ExpandListItem.ITEM,false)); } Vector v=new Vector(); v.addElement(new ExpandListItem(v1,"/img/Group-close.png","/img/Group-open.png","土匪帮",ExpandListItem.GROUP,false)); v.addElement(new ExpandListItem(v3,"/img/Group-close.png","/img/Group-open.png","警察局",ExpandListItem.GROUP,false)); v.addElement(new ExpandListItem(v2,"/img/default.png","/img/Group-open.png","法官",ExpandListItem.ITEM,false)); d.setCurrent(new ExpandList("花名册",Choice.IMPLICIT,v)); } protected void pauseApp() { // TODO Auto-generated method stub } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { // TODO Auto-generated method stub } } |