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: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia
Accepted Solution

Click on bitmapfield(image)

Hello,

         how can i perform click event on image .

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

Re: Click on bitmapfield(image)

Create a BitMapField using the image...

Make ur class implements Field Change Listner..

Set the bitmapField to this change listner..

Override the fieldChanged method....

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: Click on bitmapfield(image)

Actully what i want.

 

i have two image

 

on click of first image ..second should be display.(first image should be totaly hide ,only second imge dispalyed)

 

and now click on second image ,my first should be display

 

vise-versa

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

Re: Click on bitmapfield(image)

Hi Himanshu

 

The question you asked on your first post has been answered.

 

Do not continue on the same thread, if you need new solutions raise a new thread.

 

Thanks

Rabi

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: Click on bitmapfield(image)

setChangeListeren works for buttons.

 

and i m applying it to image ..not working

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Click on bitmapfield(image)

[ Edited ]

As rabiray pointed out earlier, BitmapField does not implement the change listener processing, so you need to extend it, if you wish to use one of these Fields, as a Button.

 

You will find the solution in this solved Thread gives you the code you need:

http://supportforums.blackberry.com/t5/Java-Development/using-image-as-button/m-p/457599#M91069

 

Also, can I recommend that you search the forum for solutions to problems before you post questions.  The issue of using images as buttons has been raised many times in the past and it would surprise me if you had not found something to help you.  So if you had searched, you would have found your solution a lot earlier I suspect. 

 

I recommend you have a search round to see what other people have done with your problem anyway, look for "Image button" for example. 

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

Re: Click on bitmapfield(image)

Hi Himanshu

 

Totally agree with @peter

 

There are many ways to achieve this functionality...Search in this forum and in stack overflow.

You will get lots fo solutions posted by developers.

 

Thx

Rabi

Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: Click on bitmapfield(image)

[ Edited ]

HI HImanshu,

 

Use this code, this is 100% according to your need.

Feel free to press cudo, if this code help you. 

 

package pk;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;

public class pk extends UiApplication{
public pk() {
	// TODO Auto-generated constructor stub
	pushScreen(new pawan());
}
public static void main(String args[])
{
new pk().enterEventDispatcher();
}
}

class pawan extends MainScreen
{
public pawan() {
	// TODO Auto-generated constructor stub
	add(new clickImg(Bitmap.getBitmapResource("button2.png"),150,60,true));
}
}

class clickImg extends BitmapField
{
boolean check=false;
Bitmap bitmap;
int width=0;
int height=0;
	clickImg(Bitmap bmp, int width, int height, boolean bl)
	{
		super(bmp, FOCUSABLE);
		check=bl;
		bitmap=bmp;
		this.width=width;
		this.height=height;
	}

	protected boolean navigationClick(int status, int time)
	{
		fieldChangeNotify(1);
		if(check==true)
		{
			this.setBitmap(Bitmap.getBitmapResource("button3.png"));
			check=false;
		}
		else
		{
			this.setBitmap(bitmap);
			check=true;
		}
		return true;
	}
	}

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Click on bitmapfield(image)

Interesting code, Sorry to be critical but I would change a few things to improve it.

 

1) I would pass in both the Bitmaps, the first and the second, so that you don't load the alternate bitmap every time it changes.

 

2) I don't know why you include a height and width in the constructor.  Should be removed.

 

3) Calling invalidate() in the constructor does nothing useful.  Should be removed.

 

4) I would allow the user to pass in some Styles, so that they could choose the BitmapField to be aligned Right or Left or whatever BitmapField supports...

 

5) You don't need to include a trackwheelClick unless you are planning on supporting very old devices with a scroll wheel.

Highlighted
Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: Click on bitmapfield(image)

Thanks Peter,

I will keep in mind these things.