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
Developer
bbvasan
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100
Accepted Solution

Checkbox Condition Tips Required

Hi,

 

I have done something similar to remember login function.But only thing i am missing is,

 

By default checkbox should not be enabled.Once the user login first time  and checks check box it should save and when next time the user logs in the checkbox should be checked by default.In same manner if he uncheks next time it should be unchecked as usual when he tries to authenticate another time.So this condition alone not working in coding.So please give me some idea of how i can do this?:smileyindifferent:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Checkbox Condition Tips Required

I think, you need a persistance Storage.

B'coz the information about the user you have to stored. and when the application runs then check all the stored data.

------------------------------------------------------------------------------------

Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

Developer
bbvasan
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100

Re: Checkbox Condition Tips Required

Hi,

 

Yes have did those all only thing i am strucked is checking unchecking check box in above condition.IT alone matters little ...:smileyhappy:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Developer
vivart
Posts: 147
Registered: ‎08-27-2010
My Device: 9800

Re: Checkbox Condition Tips Required

you can use Persistent store

 

 

public class Store {

	static PersistentObject store;
	static {
	store = PersistentStore.getPersistentObject( 0xa1a569278238dad2L );
	}
	public static void add(boolean isChecked){
		Boolean remember = new Boolean(isChecked);
		synchronized(store) {
		store.setContents(remember); 
		store.commit();
		}
	}
	public static boolean get(){
		boolean isChecked;
		synchronized(store) {
			Boolean currentinfo = (Boolean)store.getContents(); 
			if(currentinfo==null){
				isChecked = false;
			}else{
				isChecked = currentinfo.booleanValue();
			}
			
	}
		return isChecked;
	}
}

 

final CheckboxField cbf = new CheckboxField("remember me", Store.get());
        	cbf.setChangeListener(new FieldChangeListener(){

				public void fieldChanged(Field field, int context) {
				
					Store.add(cbf.getChecked());
					
				}
        		
        	});

 

 

 

 

Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Checkbox Condition Tips Required

If you are using JDE 5.0 or above Then you can use SqLite Database. and put one boolean field. that is true or false. When the application run then check what it is.

------------------------------------------------------------------------------------

Press Kudo to say thank to developer. Also Press the Accept as solution Button when u got the Solution.

Developer
bbvasan
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100

Re: Checkbox Condition Tips Required

Hi,

 

Sorry i am using JDE 4.2.That is problem.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Checkbox Condition Tips Required

Then in persistant Store, you can save data for checkBox in the form of 0 and 1.

------------------------------------------------------------------------------------

Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

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

Re: Checkbox Condition Tips Required

Can you tell us if your problem is

1) setting the value so that it display correctly on the screen, or

2) saving the value so that you know what it was set to the next time you use it?

Developer
bbvasan
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100

Re: Checkbox Condition Tips Required

Hi peter,

 

Setting the value. I mean for me saving in persistent store works perfect.But only thing is missing as other authentication system for example google Stay sign in.Once we check the box it will remain checked ever until we uncheck it.But for me in application once we close and came in it remains unchecked but restores the password correctly that is the trouble

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Developer
peter_strange
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Checkbox Condition Tips Required

Say you have this:

 

CheckboxField _checkField = new CheckboxField("Don't ask me again?", false);

 

Then, in your code, you can say:

 

boolean mySavedCheckValue = <get from persistent store>

_checkField.setChecked(mySavedCheckValue);

 

Then the Field will be checked or not depending on your stored value. 

 

Does this help?