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: 57
Registered: ‎09-12-2008
My Device: Not Specified
Accepted Solution

Problem deleting contents in ths listfield.

Hi,

  I'm loading some data in the listfield. On a button click event i want to delete all items in the listfiled.

 

deleting loop used my me:

 

               for(int y=0;y<pilllist.getSize();y++)
                {
                    pilllist.delete(y);
                }

 

before this action i had 9 items in the list. But after this loop i'm still having 4 elements left in the list. I dont know why? and how its missing 4 items.

 

but i used the same loop to display the contents in the listfied.

                for(int y=0;y<pilllist.getSize();y++)
                {
                    Dialog.inform("Current Content "+y +" "+myCallback.get(pilllist,y));
                }

 but in this loop i'm getting all the data and its displaying in the Dialog box.

 

1.Can any one tell me where i'm going wrong?

 

2.is there any other way to clear the contents in the List?

 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem deleting contents in ths listfield.

you cange the condition of your loop within it. if you copy the size into a variable before the loop your code should work.
----------------------------------------------------------
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
Highlighted
Developer
Posts: 57
Registered: ‎09-12-2008
My Device: Not Specified

Re: Problem deleting contents in ths listfield.

Thanks Simon,

 

               I found where i was wrong. Thanks for the reply

Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: Problem deleting contents in ths listfield.

can you please post the code where you were wrong? since i am having the same problem and could not find the solution.

 

i tried what simon has suggested but still the screen shows the ARRAYINDEXOUTOFBOUND EXCEPTION and when clicked on it , it removes the element in slots say of four each. i cant figure out where i'm wrong.

 

for (int i = 0; i < size; i++)
{
	_list1.delete(i);
}
_list1.invalidate();	

 

please guide me?

Swapnil G.
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem deleting contents in ths listfield.

you have to remove the element from both the listfield and the data structure that is used to fill it

----------------------------------------------------------
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
Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: Problem deleting contents in ths listfield.

i tried to remove from the data structure and also from the list but still it is giving me arrayindexoutofbound exception. how i did is like this...

 

 

if(lbl.equalsIgnoreCase("Clear"))
{
	for (int i = 0; i < size; i++)
	{					
	_list1.delete(i);
	}
	_Callback.erase();
	_list1.invalidate();				
}

 i have just fired the event on the button click.

Swapnil G.
Trusted Contributor
Posts: 200
Registered: ‎02-22-2010
My Device: BlackBerry 9550
My Carrier: Airtel

Re: Problem deleting contents in ths listfield.

for (int i = size; i > 0; i--)
{				
System.out.println("Value   "+i);			
_list1.delete(i);
}
_Callback.erase();		
_list1.invalidate();	

 hi simon,

                is this what i should try? since when i tried this it worked perfect for  me? but will it work for all times?

Swapnil G.