BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-21-2009, 05:58 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 9530
PIN: N/A
Carrier: o2
Posts: 35
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Please put me out of my misery

Please Login to Remove!

I have been trying to research and understand the concept of listfield, objestlistfield andd listfieldcallback.

I currently have a objectlistfield showing results from a search with http connection. when i get the results it's in one big string, i split the string and recreate the objects, basically 5 string variables, I then have the toString displayed in objectlistfield for each object(all 5 variables printed). I have been trying to learn how to JUST get the name variable showing in the objectlistfield. I know I could do this with the .tostring and just display one variable for each object but i need the other string variables going with it as when the object is selected I go on to re-create the object which is an extension of screen so i can see all the variables in a screen.

My last 5 hours have been wasted attempting to extend objectlistview and then override it's drawlistrow method which i use to access variables from the class vector and then drawText for just one of these of these variables and then hopefully a picture. have I misunderstood the concept? I'm thinking that the objectListField row is created by the drawlistrow method so whatever i put in that method will be put in the row, is that right/wrong?

Please help a desperate man!
Offline  
Old 08-21-2009, 07:04 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2008
Model: none
PIN: N/A
Carrier: none
Posts: 26
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try something like this

Code:
class MyGrid extends ListField implements ListFieldCallback {

    private MyData[] data;

    public MyGrid(MyData[] data) {
        setCallback(this);
        this.data = data;
    }

    public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
    	MyData row = (MyData) get(listField, index);
        // draw some stuff
        Bitmap b = Bitmap.getBitmapResource(row.icon);
        g.drawBitmap(0, y, 16, 16, b, 0, 1);
        int indent = 24;
        g.drawText(row.string, indent, y, Graphics.ELLIPSIS, width - indent);
    }

    public Object get(ListField listField, int index) {
        return data[index];
    }

    public int getPreferredWidth(ListField listField) {
        return Display.getWidth();
    }

    public int indexOfList(ListField listField, String prefix, int start) {
        return getSelectedIndex();
    }

    public int getSize() {
        return (data != null) ? data.length : 0;
    }
    
    class MyData {
    	String string;
    	String icon;
    }
}
Offline  
Old 08-22-2009, 08:00 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 9530
PIN: N/A
Carrier: o2
Posts: 35
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default thank you

your post was exactly the concept i was ooking for and i have almost got it, I just don't get the image on screen even though it's there, I think i'll get it!

Last edited by brendanmc25 : 08-22-2009 at 08:31 AM.
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.