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
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to implement custom llistfield having alternate color in row

Looks OK, but the proof is in the pudding as they say - so does it work?

Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: How to implement custom llistfield having alternate color in row

Hello sir ..!!! i override the method drawFocus() method .focus is display on the row thanks..can you explain this this methods ..actually the focus is display on row is not default(blue) some other color .?

can you please help me making this as a customList (a class )same thing as i did here so that i used that class object .actually list i used list so much time in my project but problem is that in list there are different number of columns
Example first list : only two column
Second list :four coloum are there

i need one parameter in his constructor to adjust the nummber of column
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to implement custom llistfield having alternate color in row

The best place to start when explaining how things work is the documentation - have you looked up the methods used in the supplied code to see what it is doing?  Which parts do you not understand?

 

Regarding creating code for you - sorry I don't have time to do specific things like this and besides you get paid for that not me!  What you are asking for is a variable number of columns, and as has already been pointed out, that is just dividing the width you have by the number of columns you want to display, then painting the columns.  The code you already have on this Thread is a pretty good sample for you

 

BTW, it has been suggested that to calculate the width of the columns, you use Display.getWidth().  Don't.  Use the width that gets passed in to drawListRow(). 

Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: How to implement custom llistfield having alternate color in row

Ok thanks
Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: How to implement custom llistfield having alternate color in row

How to get default focus on the row..? mean blue focus on the row
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to implement custom llistfield having alternate color in row

What do you currently see?  Can you figure out why you see it?

Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: How to implement custom llistfield having alternate color in row

Hello sir ..i see Gray color due to alpha to to override draw method..?

 

protected void drawFocus (Graphics graphics, boolean on)
{
XYRect rect = new XYRect();
graphics.setGlobalAlpha(150);
getFocusRect(rect);
drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true,rect.x,rect.y,rect.width,rect.height);
}

 

i need defult blue color on focus of row..can it is possible..?

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

Re: How to implement custom llistfield having alternate color in row

"I see Gray color due to alpha to to override draw method..?"

 

I would agree, and to check you could change this method and see if you are correct!

 

The problem you have is that you are setting the background color.  The ListField expects that you will just paint over its current background. Then to indicate focus it paints the blue background.  If you wish to retain that behavior, then you can not set the background when you are painting the focused row. 

 

This is not the way I do it (my method is slightly more complicated), but I think the easiest way to do this is to set a flag in drawFocus, call super.drawFocus, reset the flag when the super.drawFocus returns. Then in your drawListRow method, check to see if this flag is set, and if so, don't set the background color. 

 

Give this a go, and let us know how you get on. 

Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: How to implement custom llistfield having alternate color in row

Hello 

 

i do like this ....

 

first i declare hasfocus varible .then i  enter in 

 

	public void drawListRow(ListField listField, Graphics graphics, int index,
			int y, int width) {
		int curSelected;
		    if(!hasFocus){
		    if(index%2  == 0){
			
			graphics.setColor(Color.RED); 
			graphics.fillRect(0, y, width, listField.getRowHeight());
			graphics.setColor(Color.WHITE); 
			
			}else{
			graphics.setColor(Color.BLACK); 
			graphics.fillRect(0, y, width, listField.getRowHeight());
			}
		    }
			//graphics.fillRect(0,0,width,y);
			 
			int xpos = 0;int ypos = 0;
			graphics.setFont(Font.getDefault());// please set a font value
			// this is first column text
			graphics.setColor(Color.PINK); 
			graphics.drawText("column1"+index,xpos,y);
			xpos +=  columnWidth;
			 
			//graphics.setColor(Color.RED); 
			graphics.drawText("column2",xpos,y);
			 
			xpos +=  columnWidth;
			graphics.drawText("column3",xpos,y);
			 
			xpos +=  columnWidth;
			 
			graphics.drawText("column4",xpos,y);
		
	}

 

what i have to do in this code ? can you explain ?

protected void drawFocus(Graphics graphics, boolean on) {
					//hasFocus = true;
					super.drawFocus(graphics, on);
					//hasFocus = false;
//					XYRect rect = new XYRect();
//				graphics.setGlobalAlpha(200);
//					getFocusRect(rect);
//					drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true,rect.x,rect.y,rect.width,rect.height);
				}
			
				
				public void onFocus(int direction) {
					hasFocus = true;
					super.onFocus(direction);
				}

				// Invoked when a field loses the focus.
				public void onUnfocus() {
					hasFocus = false;
					super.onUnfocus();
					invalidate();
				}

 

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

Re: How to implement custom llistfield having alternate color in row

[ Edited ]

I had not expected you to add onFocus or onUnfocus methods.  All I expected was this:

 

protected void drawFocus(Graphics graphics, boolean on) {
 hasFocus = true;
super.drawFocus(graphics, on);
 hasFocus = false;

}

Please use plain text.