我正在制作一个列表,其中包含人和每个人的评分作为单元格背景,该列表为每个单元格提供相同的评分背景,但是当向上或向下滚动列表时,我正在拖动的单元格采用它的真实速率背景,但其他单元格保持相同速率的背景图像我正在使用诺基亚 s40 全触摸模拟器这是我用于单元格渲染器的代码
list.setRenderer(new ListCellRenderer() {
public Component getListFocusComponent(List list) {
// TODO Auto-generated method stub
return null;
}
public Component getListCellRendererComponent(List list,
Object value, int index, boolean isSelected) {
String rate = "";
rate = Transportation.getDriverRate(value.toString(),
CityListForm.selectedCity);
rate = (Integer.parseInt(rate)) > 25 ? "" + 5 : ""
+ Integer.parseInt(rate) / 5;
rate = "/" + rate + ".png";
Image image = null;
Label label = null;
try {
image = (Image.createImage(rate));
System.out.println(rate);
} catch (IOException e) {
e.printStackTrace();
}
label = new Label();
label.getStyle().setBgImage(image);
label.setText(value.toString());
label.getStyle().setAlignment(RIGHT);
label.setTextPosition(RIGHT);
Style style = label.getStyle();
style.setBgColor(16777215);
style.setFgColor(0);
label.setPreferredH(42);
return label;
}
});