Hi streamh,
Quote:
Originally Posted by streamh Hi,ARIF:
I have searched the drawListRow() method in the ListFieldCallback, but the API has a simple description of it. It just explains the parameters of the method and does not contain any demo.
Could you show some demo about this?Thank you very much for your help! |
Here is a sample code with implementation of ListFieldCallback:
Code:
private class ListCallback implements ListFieldCallback {
private Bitmap LIST_IMAGE = Bitmap.getBitmapResource("list.gif");
private Vector listElements = new Vector();
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
String text = (String)listElements.elementAt(index);
g.drawBitmap(0, y, LIST_IMAGE.getWidth(), LIST_IMAGE.getHeight(), LIST_IMAGE, 0, 0);
g.drawText(text, 50, y, 0, w);
}
public Object get(ListField list, int index) {
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String p, int s) {
return listElements.indexOf(p, s);
}
public int getPreferredWidth(ListField list) {
return Graphics.getScreenWidth();
}
public void insert(String toInsert, int index) {
listElements.insertElementAt(toInsert, index);
}
} And add the following code where you do like to add the list on your screen:
Code:
ListField list = new ListField();
ListCallback callback = new ListCallback();
list.setCallback(callback);
for (int index=0; index<5; index++) {
list.insert(index);
callback.insert("Row"+index, index);
}
add(list); Enjoy!
ARIF