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
uikro
Posts: 13
Registered: ‎11-21-2012
My Device: 8530
My Carrier: 07066868124

Updating/Refreshing a ListField

I Loaded a ListField with a vector from a ButtonField Click. When the button is clicked the first time, it fill the ListField and on second click it fill the ListField again causing the ListField to have Duplicate Values or element. How do i refresh a ListField?

Please use plain text.
Developer
tklanilkumar
Posts: 206
Registered: ‎02-22-2011
My Device: BB TORCH & 9800
My Carrier: idea

Re: Updating/Refreshing a ListField

We have to see what you are doing on clicking on button, So post your code. so that we may help you asap.

Regards
Anil
*****************************************************************************
* Give kudos when you like it
* Mark it as a solution if it fixes your issue
Please use plain text.
Contributor
uikro
Posts: 13
Registered: ‎11-21-2012
My Device: 8530
My Carrier: 07066868124

Re: Updating/Refreshing a ListField

check the code below

--------------------------------------------------------------------

 

public final class MyScreen extends MainScreen implements FieldChangeListener, ListFieldCallback
{
/**
* Creates a new MyScreen object
*/
private ListField listUsers;
//protected EditField _CopyString = new EditField();
UsersList vectorUsers = new UsersList();
public MyScreen()
{
super(Manager.NO_VERTICAL_SCROLL);
// Set the displayed title of the screen
Manager mainManager = getMainManager();
setTitle("My List & Vector Example");
ButtonField btnUsers = new ButtonField("Get");
btnUsers.setChangeListener(this);
add(btnUsers);


}
public void fieldChanged(Field field, int context) {
Manager mainManager = getMainManager();


RichList list = new RichList(mainManager, true, 1, 0);
Bitmap bitmap = Bitmap.getBitmapResource("icon.png");
for(int i=1; i<vectorUsers.addItem().size(); i++){
list.add(new Object[] {bitmap, vectorUsers.addItem().elementAt(i)});
}
invalidate ();
}
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
String personToDraw = (String) this.get(list, index);
int drawColor = Color.RED;
g.setColor(drawColor);
g.drawText(personToDraw, 0, y, 0, w);
}

// get the selected index from the correct Vector
public Object get(ListField list, int index) {
return vectorUsers.addItem().elementAt(index);
}

public void insert(String toInsert, int index) {
vectorUsers.addItem().insertElementAt(toInsert, index);
}


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

public int indexOfList(ListField listField, String prefix, int start) {
return vectorUsers.addItem().indexOf(prefix, start);
}

}

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Updating/Refreshing a ListField

Please use plain text.