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
New Developer
Posts: 34
Registered: ‎03-12-2012
My Device: blackberry tourch
Accepted Solution

urgent help in accessing bitmaps

Draft

dear all,

i have 4 images as bitmaps and i would like to click on each one of them and each one will take me to other screen for example :

image 1 --> navigation click --> go to screen 1

image 2 --> navigation click --> go to screen 2

image 3 --> navigation click --> go to screen 3

image 4 --> navigation click --> go to screen 4

all of these 4 images are in 1 screen.

 

 

how can i make this?

i know how to work with 1 image. if i have 1 image only in the screen

but if i have more than 1 images i tried many possible ways to click or touch but nothing i have recieved..

 

i tiried to use them in HorizontalFieldManager.. by creating numbers of Field Managers but only 1 manager is displayed on screen

also i tried to use them in pain method, also nothing // error code

what else????

 

waiting for your urgent replay.

regards,

 

 
Developer
Posts: 16,510
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: urgent help in accessing bitmaps

maybe the image button from the advanced samples helps you out:
http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-manage...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold

Re: urgent help in accessing bitmaps

On navigation click methodm, check which field has got the current focus and launch the screen accordingly.

 

 

New Developer
Posts: 34
Registered: ‎03-12-2012
My Device: blackberry tourch

Re: urgent help in accessing bitmaps

rabiray, your way is suitable for my code, i 'll show sample of my code and try to add something .. beacuse may i miss understand you

 

public EnglishStoryListHear() 
    {
    	
    	super();
    	 // Set the displayed title of the screen       
       setTitle("English Story List to Hear ");
       
        _bitmaps = Bitmap.getBitmapResource("peter_rabbit.png");
        _bitmaps2 = Bitmap.getBitmapResource("little_red.png");
     
        HorizontalFieldManager _Hmanager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT){
            
            //Override the paint method to draw the background image.
            public void paint(Graphics graphics)
            {
                //Draw the background image and then call paint.
                graphics.drawBitmap(0, 0,950, 400, _bitmaps, 0, 0);
                graphics.drawBitmap(0, 80,800, 300, _bitmaps2, 0, 0);
              
                super.paint(graphics);
            }            
           
        };
       
     	addMenuItem(_HomeItem);
     	addMenuItem(_HelpItem);
     	add(_Hmanager);
     	
   
    }

 and this is click navigation method i do:

protected boolean navigationClick(int time,int state)
        	{
        		 fieldChangeNotify(0);
        		 UiApplication.getUiApplication().pushScreen(new ArabicStoryListHear());
        		 return true;
        	}

 so, what are the changes i have to do in navgation click method?

Developer
Posts: 16,510
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: urgent help in accessing bitmaps

a bitmapfield is not focusable by default, and even if created focusable it does not show that it has the focus, so better use the imagebutton from the link i gave you above or search the forum for this topic.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold

Re: urgent help in accessing bitmaps

Yes,

 

You can not focus a Bitmap on its own...

 

U need to create BitmapFields using Bitmap and add them to he horizontal manager.  (hfm)

say bitMapFld1, bitMapFld2

 

Now on navigationClick , check 

Field fld  = hfm.getFieldWithFocus()

if (fld == bitMapFld1)

Launch Screen1

if (fld == bitMapFld2)

Launch Screen2

 

 

Hope this helps.

 

New Developer
Posts: 34
Registered: ‎03-12-2012
My Device: blackberry tourch

Re: urgent help in accessing bitmaps

[ Edited ]

ok simon, i am trying now using

ListStyleButtonField, beacuse this is what i need , i am listing stories and this field is suitable for my current App

..

its really cool .. :smileyvery-happy:

 

please may i need your help later, try to be available

 

New Developer
Posts: 34
Registered: ‎03-12-2012
My Device: blackberry tourch

Re: urgent help in accessing bitmaps

brother,

 

i have created one

ListStyleButtonField successfully, but once i tried to create another one with following the same method...

this

ListStyleButtonField 2 doesn't appear in the screen...

 

thats mean, only one button field is shown in the screen the other one is not..

 

story1=new ListStyleButtonField("little red ridding hood",Field.FIELD_RIGHT); story2=new ListStyleButtonField("peter rabbit",Field.FIELD_RIGHT );  story2.setDrawPosition(100); HorizontalFieldManager h_tab_Manager = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER | HorizontalFieldManager.FIELD_VCENTER); h_tab_Manager.add(story1); h_tab_Manager.add(story2); add(h_tab_Manager);

 and this is the new code i have made ..

 

any other help ?

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

Re: urgent help in accessing bitmaps

[ Edited ]

Hi ManarS

 

Try this Code

 



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

public class pkj extends MainScreen{
	clickImg btn1,btn2,btn3,btn4;
public pkj() {
	// TODO Auto-generated constructor stub
	HorizontalFieldManager hfm = new HorizontalFieldManager();
	
	btn1 = new clickImg(Bitmap.getBitmapResource("icon1.png"),true);
	btn2 = new clickImg(Bitmap.getBitmapResource("icon2.png"),true);
	btn3 = new clickImg(Bitmap.getBitmapResource("icon3.png"),true);
	btn4 = new clickImg(Bitmap.getBitmapResource("icon4.png"),true);
	
	hfm.add(btn1);
	hfm.add(btn2);
	hfm.add(btn3);
	hfm.add(btn4);
	add(hfm);
}
protected boolean navigationClick(int status, int time) {
    Field _field = UiApplication.getUiApplication().getActiveScreen().getLeafFieldWithFocus();
    try {
    	if(_field == btn1)
    	{
    		UiApplication.getUiApplication().pushScreen(new Screen1());
    	}
    	if(_field == btn2)
    	{
    		UiApplication.getUiApplication().pushScreen(new Screen2());
    	}
    	if(_field == btn3)
    	{
    		UiApplication.getUiApplication().pushScreen(new Screen3());
    	}
    	if(_field == btn4)
    	{
    		UiApplication.getUiApplication().pushScreen(new Screen4());
    	}
    } catch (Exception e) {
            System.out.println("Exception : :: navigationClick() :: "+ e.toString());
    }
    return true;
}
}

 
class clickImg extends BitmapField
{
boolean check=false;
Bitmap bitmap;

	clickImg(Bitmap bmp, boolean bl)
	{
		super(bmp, FOCUSABLE);
		check=bl;
		bitmap=bmp;
	}

	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;
	}
	}

 

Thanks

Pawan

 

New Developer
Posts: 34
Registered: ‎03-12-2012
My Device: blackberry tourch

Re: urgent help in accessing bitmaps

hello Pawan,

 

your code is nice but i found an error in these 2 statements ..

 

 

clickImg	_chocoImg = new clickImg(Bitmap.getBitmapResource("chocolate_1.png"),true​);
   clickImg	_lemonImg = new clickImg(Bitmap.getBitmapResource("lemon_1.png"),true​);

 the error is :

Syntax error on token "Invalid Character", delete this token

 

 

so how can i fix this ?!!