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
Highlighted
Trusted Contributor
Posts: 115
Registered: ‎11-16-2011
My Device: Smartphone Storm 9900
My Carrier: 3
Accepted Solution

how to make array list decrement on listField ?

im create code like this:

public class ScreenList extends MainScreen implements ListFieldCallback{
	String x[];
	ListField list;
	public ScreenList(){
		String arr[] ={"1", "2","3","4","5","6"};
		list = new ListField();
		
		int length = arr.length;
		x = new String[ length];
		for(int i=length-1; i>=0; i--){
			x[i]=arr[i];
			//add(new LabelField(arr[i]);
		}
		list.setSize(length);
		list.setCallback(this);
		this.add(list);
	}


	public void drawListRow(ListField arg0, Graphics arg1, int index, int y,
			int width) {
		// TODO Auto-generated method stub
		arg1.drawText(x[index], 0, y);
		
	}

 if i try on simulator on simulator still print 1,2,3,4,5,6 but if i try to print with new Label result 6,5,4,3,2,1

my question... how to make list decrement with listField implements callback? thanks for advance...

Contributor
Posts: 17
Registered: ‎12-20-2011
My Device: Bold 9780
My Carrier: Vodafone

Re: how to make array list decrement on listField ?

Your for loop is not correct. If you want to print nos in reverse direction replace your drawListRow by following

 

public void drawListRow(ListField arg0, Graphics arg1, int index, int y,
			int width) {
		int len = x.length;
		arg1.drawText(x[ len - index ], 0, y);
		
	}
Contributor
Posts: 17
Registered: ‎12-20-2011
My Device: Bold 9780
My Carrier: Vodafone

Re: how to make array list decrement on listField ?

OR you can write it in this way 

public class ScreenList extends MainScreen implements ListFieldCallback{
	String x[];
	ListField list;
	public ScreenList(){
		String arr[] ={"1", "2","3","4","5","6"};
		list = new ListField();
		
		int length = arr.length;
		x = new String[ length];
		for(int i=0; i<lenght; i++){
			x[i] = arr[ length - i ];
		}
		list.setSize(length);
		list.setCallback(this);
		this.add(list);
	}


	public void drawListRow(ListField listField, Graphics graphics, int index, int y,
			int width) {
		
		graphics.drawText(x[index], 0, y);
		
	}
Trusted Contributor
Posts: 115
Registered: ‎11-16-2011
My Device: Smartphone Storm 9900
My Carrier: 3

Re: how to make array list decrement on listField ?

i try ur both way...and test on simulator getting error... "Uncought exception: Index 6>=6"

anything wrong?

Contributor
Posts: 17
Registered: ‎12-20-2011
My Device: Bold 9780
My Carrier: Vodafone

Re: how to make array list decrement on listField ?

oops sorry small correction instead of length use length -1
Trusted Contributor
Posts: 115
Registered: ‎11-16-2011
My Device: Smartphone Storm 9900
My Carrier: 3

Re: how to make array list decrement on listField ?

yes..it's worked...thanks for solutions and fast respons...