我想要在文本右侧带有图像和复选框的列表字段。我在左侧获得了图像,但无法在右侧获得复选框。如果可能,复选框应该是不可见的。只应看到刻度线。我想实现
Image text1 chechbox
Image text2
Image text3 checkbox
所有列表项的图像应该相同。
public final class ListfieldDemo1 extends MainScreen
{
private Vector _listElements;
ListField list;
private ListField _checkList;
public ListfieldDemo1()
{
// Set the displayed title of the screen
super(Manager.NO_VERTICAL_SCROLL);
add(new LabelField("Fruits List", LabelField.FIELD_HCENTER));
add(new SeparatorField());
setTitle("ListField with images and checkbox");
_listElements = new Vector();
add(new SeparatorField());
list = new ListField();
ListCallback _callback = new ListCallback(this);
list.setCallback(_callback);
list.setSize(4);
int index = list.getSelectedIndex();
add(list);
createField();
}
protected void createField()
{
String itemOne = "Apple";
String itemTwo = "Blackberry";
String itemthree ="Grapes";
String itemfour = "Banana";
_listElements.addElement(itemOne);
_listElements.addElement(itemTwo);
_listElements.addElement(itemthree);
_listElements.addElement(itemfour);
reloadList();
}
private void reloadList() {
list.setSize(_listElements.size());
}
public boolean invokeAction(int action)
{
switch (action)
{
case ACTION_INVOKE: // Trackball click.
return true;
}
return super.invokeAction(action);
}
class ListCallback implements ListFieldCallback
{
private static final int LEFT_OFFSET = 10;
private static final int TOP_OFFSET = 10;
ListfieldDemo1 listfieldDemo1;
public ListCallback(ListfieldDemo1 listfieldDemo1)
{
this.listfieldDemo1 = listfieldDemo1;
}
public void drawListRow(ListField listField, Graphics g, int index,
int y, int w) {
String text = (String)_listElements.elementAt(index);
g.drawText(text, 60, y + 5, 0, w);
text = (String) _listElements.elementAt(index);
Bitmap bitm = Bitmap.getBitmapResource("bullet_arrow.png");
int xpos = LEFT_OFFSET;
int ypos = TOP_OFFSET + y;
w = bitm.getWidth();
int h = bitm.getHeight();
g.drawBitmap(xpos, ypos, w, h, bitm, 0, 0);
xpos = w + 20;
}
public Object get(ListField listField, int index) {
// TODO Auto-generated method stub
return null;
}
public int getPreferredWidth(ListField listField) {
// TODO Auto-generated method stub
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
// TODO Auto-generated method stub
return 0;
}
}
}
提前致谢。