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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

save fonts

i have used object choice field to change the font of text in label, that is working fine, and tha fonts are changing. but when i close the app and open the app again, i want to show that selected font when i apply the font before closing the app

for eg= first time i have selected a font form object choice field and apply to my text in label. and i close the app. and when i open the app again i want to show that selected font to the text in label

9630.png

 

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: save fonts

you can store the index in a persistant object. check the api and developer guide for details.
----------------------------------------------------------
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
Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

plz could you explain it more,i mean storing the index in persistant object.
Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: save fonts

This tutorial is designed to help you learn about this yourself.

http://supportforums.blackberry.com/t5/Java-Development/Storing-Persistent-Data/ta-p/442785

 

I recommend that you work through this. 

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

[ Edited ]

yes i have try these links, but they i want to show the same value which is selected by the user when the user open the app ,after closeing.i have try with PersistentObject to store but did not got success, plz can u correct me.

look at my code i used Objectchoice field to set background images. once the user set the image from Objectchoice field and when after closing the app the same image will be shown be the screen

public final class MyScreen extends MainScreen 
{
	String[] Backimages = {"image1","image2","image3","image4","image5","image6"};
	ObjectChoiceField pickSize, Background;   
    private VerticalFieldManager mainManager;
    private VerticalFieldManager subManager;
    private Bitmap _backgroundBitmap = Bitmap.getBitmapResource("a.png");       
    private int deviceWidth = Display.getWidth();
    private int deviceHeight = Display.getHeight();
    Bitmap backgroundBitmap = Bitmap.getBitmapResource("brush.png");
    String index;
    
    
    public MyScreen() 
    {
        super(NO_VERTICAL_SCROLL);
        //this manager is used for the static background image
        Background = new ObjectChoiceField("images:", Backimages,0);
        
        
        
        mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR)
        {            
          
        };
        
        //this manger is used for adding the componentes
        subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR)
        {
            protected void sublayout(int maxWidth, int maxHeight)
            {
                int displayWidth = deviceWidth;
                int displayHeight = deviceHeight;
 
                super.sublayout( displayWidth, displayHeight);
                setExtent( displayWidth, displayHeight);
            }
        };
                
        // add your component to this subManager       
        subManager.add(Background);
        Background.setChangeListener(new FieldChangeListener() {
			
			public void fieldChanged(Field field, int context) {
				// TODO Auto-generated method stub
				if(field == Background)
		         {
					 
		      	   index = (String) Background.getChoice(Background.getSelectedIndex());
		      	   System.out.println("INDEX========"+Background.getSelectedIndex());
		      	   //Dialog.alert(""+index);
		      	   if(Background.getSelectedIndex() == 0){
		      		 mainManager.setBackground(BackgroundFactory.createBitmapBackground(backgroundBitmap));
		      	   }else if(Background.getSelectedIndex() == 1){
		      		 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("c.png")));
		      	   }else if(Background.getSelectedIndex() == 2){
		      		 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("f.jpg")));
		      	   }else if(Background.getSelectedIndex() == 3){
		      		 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("g.jpg")));
		      	   }else if(Background.getSelectedIndex() == 4){
		      		 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("h.jpg")));
		      	   }else if(Background.getSelectedIndex() == 5){
		      		 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("i.jpg")));
		      	   }
		      	   		      	   
		         }  
			}
		});
        
        //add subManager over the mainManager
        mainManager.add(subManager);
        
        //finally add the mainManager over the screen
        this.add(mainManager); 
        
    } 
    
    
}

 

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: save fonts

i don't see any persistence in this code.
----------------------------------------------------------
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
Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

[ Edited ]

look at this code in listner of ObjectChoice fied ,i'm trying to store tha selected index to vector and theb store that vector in to 

 persistent store ,but the index is not storing into vector

public final class MyScreen extends MainScreen 
{
	String[] Backimages = {"image1","image2","image3","image4","image5","image6"};
	ObjectChoiceField pickSize, Background;   
    private VerticalFieldManager mainManager;
    private VerticalFieldManager subManager;
    private Bitmap _backgroundBitmap = Bitmap.getBitmapResource("a.png");       
    private int deviceWidth = Display.getWidth();
    private int deviceHeight = Display.getHeight();
    Bitmap backgroundBitmap = Bitmap.getBitmapResource("brush.png");
    String index;
    static PersistentObject store;
    static {
    	store = PersistentStore.getPersistentObject( 0xa1a569278238dad2L );
    	}
    private Vector saveimagevector; 
    
    public MyScreen() 
    {
        super(NO_VERTICAL_SCROLL);
        
        //this manager is used for the static background image
        Background = new ObjectChoiceField("images:", Backimages,0);
       
        mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR);
        mainManager.setBackground(BackgroundFactory.createBitmapBackground(_backgroundBitmap));
        
        //this manger is used for adding the componentes
        subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR)
        {
            protected void sublayout(int maxWidth, int maxHeight)
            {
                int displayWidth = deviceWidth;
                int displayHeight = deviceHeight;
 
                super.sublayout( displayWidth, displayHeight);
                setExtent( displayWidth, displayHeight);
            }
        };
                
        // add your component to this subManager       
        subManager.add(Background);
        Background.setChangeListener(new FieldChangeListener() {
			
			public void fieldChanged(Field field, int context) {
				// TODO Auto-generated method stub
				if(field == Background)
		         {
					 
		      	   try {
					index = (String) Background.getChoice(Background.getSelectedIndex());
					   System.out.println("INDEX========"+Background.getSelectedIndex());
					  
					   if(Background.getSelectedIndex() == 0){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(backgroundBitmap));
					   }else if(Background.getSelectedIndex() == 1){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("c.png")));
					   }else if(Background.getSelectedIndex() == 2){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("f.jpg")));
					   }else if(Background.getSelectedIndex() == 3){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("g.jpg")));
					   }else if(Background.getSelectedIndex() == 4){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("h.jpg")));
					   }else if(Background.getSelectedIndex() == 5){
						 mainManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("i.jpg")));
					   }
					   
					 saveimagevector.addElement(index);
					System.out.println("vector=="+saveimagevector);
					
					synchronized(store) 
					{
						store.setContents(saveimagevector); 
						store.commit();
						
					}
					
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					System.out.println(e.toString());
				}	      	   
		         }  
			}
		});
        
        //add subManager over the mainManager
        mainManager.add(subManager);
        
        //finally add the mainManager over the screen
        this.add(mainManager); 
        
    } 
    
    
}

 

 

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

Re: save fonts

Change this:

 

      saveimagevector.addElement(index);
System.out.println("vector=="+saveimagevector);

 

to this:

 

System.out.println("Saving: "+index);

      saveimagevector.addElement(index);
System.out.println("Entries in Vector: "+saveimagevector.size());

System.out.println("vector=="+saveimagevector);

 

Then tell us what entries you see as a result of this processing.  According to the listener code you should see line from the execution, starting with:

INDEX========...

 

Can you show us all the lines you see in the log after and including this line. 

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: save fonts

when i select the image2 to in the Object Choice Field ,my app will crash.and i have found following in console.and look at Pic.

FocusHistory: Focus gained; App net_rim_bb_ribbon_app; Component net.rim.device.apps.internal.ribbon[0.0] .launcher.RibbonIconField
[0.0] FocusHistory: Focus lost; App net_rim_bb_ribbon_app; Component net.rim.device.apps.internal.ribbon.l[0.0] auncher.RibbonIconField
[0.0] FocusHistory: Focus gained; App Font2; Component net.rim.device.api.ui.component.ObjectChoiceField
[0.0] FocusHistory: Focus lost; App Font2; Component net.rim.device.api.ui.component.ObjectChoiceField
[0.0] FocusHistory: Focus gained; App Font2; Component net.rim.device.api.ui.component.ChoiceField$ChangeO[0.0] ptionChoiceField
[0.0] FocusHistory: Focus lost; App Font2; Component net.rim.device.api.ui.component.ChoiceField$ChangeOpt[0.0] ionChoiceField
[0.0] INDEX========1
[0.0] Saving: image2

 Untitled.png