Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 12
Registered: ‎06-09-2011
My Device: Blackberry 7290
My Carrier: Vodafone

ListFieldCallback methods

Hello

I am not able to call the listfield call back methods in my code even after implementing the interface and using the setCallback(this)

My code is something like this

 

class A implements ListFieldCallback

{

    ListField listField;

Vector _vector=new Vector();

  public A()  // constructor

{

 
    super();

listField= new ListField();

for(conditions..)

{

  adding elements to vector....

 

 lf.setCallback(this);

}

 

       add(listField);

 

 public void drawListRow(ListField fieldVar,Graphics graphics,int index, int y, int width)
  {
     System.out.println("I am in draw list row ");
     
    if ( lf == fieldVar
    && index < vector_contact.size())
    {
  
     
      String displayName = detailFields[index].getText();
      System.out.println("The display name is  "+displayName);
     
      graphics.drawText(displayName,0,y,0, width);
    }
  }

  public Object get(ListField fieldVar, int index)
  {
     
     System.out.println("I am in List field get ");
    if (lf == fieldVar)
    {
      //If index is out of bounds an exception will be thrown,
      //but that's the behaviour we want in that case.
      //fieldVar.setSearchable(true);
      return vector_contact.elementAt(index);
    }
    return null;
  }

  public int getPreferredWidth(ListField fieldVar)
  {
      System.out.println("I am in Get preferred width ");
    //use all the width of the current LCD
    return Display.getWidth();
  }

 public int indexOfList (ListField fieldVar, String prefix,int start)
    {
          System.out.println("I am in Index of list ");
        //System.out.println("THE INDEX IN THE INDEXOFLIST FUNCTION IS "+ blackBerryContacts.indexOf(prefix,start));
       //return blackBerryContacts.indexOf(prefix,start);
      return -1; // not implemented
    }
   

 

}

 

 

 

 

Developer
Posts: 132
Registered: ‎05-07-2009
My Device: Curve
My Carrier: Vodafone

Re: ListFieldCallback methods

u dont need lf.setCallback(this) everytime in loop.

 

call it once after u initialise ur listfield

Sameer Joshi
Blackberry developer.
Contributor
Posts: 12
Registered: ‎06-09-2011
My Device: Blackberry 7290
My Carrier: Vodafone

Re: ListFieldCallback methods

Hi Sameer i hav tried that way but still i am not able to call the call back methods
i am not able to see the S.O.Ps of the callback methods in the console
Developer
Posts: 132
Registered: ‎05-07-2009
My Device: Curve
My Carrier: Vodafone

Re: ListFieldCallback methods

this code has major problems... i wonder how it is compiling at ur end...

Sameer Joshi
Blackberry developer.
Developer
Posts: 132
Registered: ‎05-07-2009
My Device: Curve
My Carrier: Vodafone

Re: ListFieldCallback methods

how u can add 

 

add(listField);

 

its not a screen....

Sameer Joshi
Blackberry developer.
Developer
Posts: 132
Registered: ‎05-07-2009
My Device: Curve
My Carrier: Vodafone

Re: ListFieldCallback methods

adding elements to vector is not enough... u need to insert in listfield and callback

Sameer Joshi
Blackberry developer.