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
Developer
Posts: 34
Registered: ‎03-08-2012
My Device: Simulator
My Carrier: Developer

Adding multiple values form database into RichList Blackberry

I am using Blackberry Plug-in and  Rich Lists of blackberry. I want to make lists appear the same number of times as there are entries in the database table. I m using the below code but it shows only one name in list view(present selected). I need to show all the entries in database into list view...Kindly help me..

I have already used list.add(); inside the for loop but it is showing Exception: java.lang.IllegalStateException: Field added to a manager while it is already parented.

 

Here i m using a bitmap which can be used as a button also.

The 'name' has name selected by user and this is to be searched in database for other information such as date-time.

The code only works when i put list.add(new Object[] {delete,name,"time-date"}); outside the for loop else it shows error.

public static void richlistshow(){

    String name = null;


    list = new RichList(mainManager, true, 2, 0);

    Bitmap logoBitmap = Bitmap.getBitmapResource("delete.png");
    delete = new BitmapField(logoBitmap, Field.FIELD_HCENTER);

    for (int c = 0; c < target_list.size();c++){

        City tar_city = new City();
        tar_city = (City)target_list.elementAt(c);

        name = tar_city.get_city_name().toString();

         }

            //adding lists to the screen
    list.add(new Object[] {delete,name,"time-date"});

}

 

Developer
Posts: 226
Registered: ‎10-01-2011
My Device: Passport

Re: Adding multiple values form database into RichList Blackberry

Hi Eraman,

 

I thnk you are best to use the ListField so you can just add hte daat to a single field and just deal with how to draw the field. Here is simple outline:

 

VerticalFieldManager manager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
add(manager);

listField = new CustomListField(_data);   // _data is a vector of records
listField.setSize(_data.size());
listField.setSelectedIndex(0); // start with
manager.add(listField);

 

CustomListField extends ListField and implements the Paint method.

 

Chris

Developer
Posts: 34
Registered: ‎03-08-2012
My Device: Simulator
My Carrier: Developer

Re: Adding multiple values form database into RichList Blackberry

I have used ListField as well as simple label field in place of rich list but there is a problem that when i put manager.add() inside for loop it doesn't work i.e. it shows Exception: java.lang.IllegalStateException: Field added to a manager while it is already parented. and when it is put outide th for loop it works fine but donot select value from database ....can u plz help me out here....
Developer
Posts: 16,647
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Adding multiple values form database into RichList Blackberry

the exception you get means that you add a field twice.
one field can only be added to one manager, if you need several fields create new instances of the class.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Adding multiple values form database into RichList Blackberry

Hi,

 

Just a thought...

 

Have u tried using 

 

 

insert(int rowIndex, Object[] data)  inside the for loop. 

 

Cheers

Rabi Ray

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Adding multiple values form database into RichList Blackberry

Hi,

 

Do not add BitmapField into List and the bitmap....

 

public static void richlistshow(){

String name = null;


list = new RichList(mainManager, true, 2, 0);

Bitmap logoBitmap = Bitmap.getBitmapResource("delete.png");
//delete = new BitmapField(logoBitmap, Field.FIELD_HCENTER);

for (int c = 0; c < target_list.size();c++){

City tar_city = new City();
tar_city = (City)target_list.elementAt(c);

name = tar_city.get_city_name().toString();

//adding lists to the screen
list.add(new Object[] {logoBitmap,name,"time-date"});

}

 

}

 

This is not throwing any error...should work

 

Thx

Rabi

 

Developer
Posts: 34
Registered: ‎03-08-2012
My Device: Simulator
My Carrier: Developer

Re: Adding multiple values form database into RichList Blackberry

but if i want to add a button in place of bitmap then what???
can button be added to richlist or listfield????
Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: Adding multiple values form database into RichList Blackberry

public void add(Object[] data)
Adds an array of data to the bottom of the RichList. If the "Image Space" is being used, the first item in the array must be a Bitmap object. 
I hope this answer ur question.