Search This Blog

Thursday, 14 June 2012

How to get touchevent on any field in Blackberry.

Hello friends,
                     Here is something interesting , what if you wana use some icons in your app and want to do something on click like for simplicity change that icon on click ....here it is a simple code...

Code:

Suppose we have a png image in res folder with the name 'abc.png'

So, first we initialize and declare a BitmapField...

Bitmap _icon = Bitmap.getBitmapResource("abc.png");
Bitmap _iconClick = Bitmap.getBitmapResource("abcClick.png");
BitmapField _icon1 = new BitmapField(_icon){
//Now we do something on Click on this BitmapField

public boolean touchEvent(TouchEvent message){
    if(message.getEvent()==TouchEvent.CLICK){
       //Do something on click here

       //Change the icon on Click
       this.setBitmap(_iconClick);
       return true;
   }

return false;
}
};



4 comments:

  1. nice idea !! are you sure it will work??

    ReplyDelete
    Replies
    1. yes buddy, i always follow this strategy instead using buttons i use BitmapFiuelds and call their touchEvent method ....this way i can use anything as a button ...you can also change the Bitmap on click to give it a perfect button effect.I am using a glow effect , whenever a user clicks the next bitmap is displayed with a glow ...that gives a nice effect

      Delete
  2. and one thing more friend, you can try other features alos like hover,down,gesture etc....its fun to do different things on touch

    ReplyDelete
  3. heyyy thanx..!! will ask you more but let me try this first.

    ReplyDelete