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

listener with custom class not getting invoked...

hi all,

       i have extended the customclass with the field. i had drawn a rounded rectangle in it. now i want that the listener should get invoked when i click on the rectangle and dialog should appear. i has handled the setchangelistener but of no use. here is my code...

package com.samples;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class CustomPaintingScreen extends MainScreen implements FieldChangeListener
{	
	public CustomPaintingScreen()
	{
		setTitle("Custom Painting ");
		CustomClass cstmcls = new CustomClass();	
		cstmcls.setChangeListener(this);		
		add(cstmcls);
         }

	public void fieldChanged(Field field, int context)
	{
		if(field instanceof CustomClass)
		{
			Dialog.alert("clicked");
		}
	}
}
-----------------
package com.samples;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;


public class CustomClass extends Field 
{
	protected void layout(int width, int height)
	{
		height = getFont().getHeight()* 8;		
		setExtent(Display.getWidth(), height);		
	}

	protected void paint(Graphics graphics)
	{
		graphics.setColor(0xFF7F24);		
		graphics.fillRoundRect(5, 5, (getWidth()-10), (getFont().getHeight()*5), 30, 40);
	}
}

 

 

on click of the rounded rectangle i want to display the alert message.

1708iE4A95A86FAA0FDFF

Swapnil G.
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: listener with custom class not getting invoked...

Have a look at the use of fieldChangeNotify in this Thread to resolve your problem:

 

http://supportforums.blackberry.com/t5/Java-Development/setChangeListener-doesn-t-catch-on-custom-bu...

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

Re: listener with custom class not getting invoked...

i tired to read that post but can't get exactly what to do? can anybody plz explain me more...

Swapnil G.
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: listener with custom class not getting invoked...

The essential code in that post is this:

 

protected boolean navigationClick(int status, int time) {
    fieldChangeNotify(1);   
    return super.navigationClick(status, time);
}