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
Regular Contributor
DingDang
Posts: 61
Registered: ‎03-28-2010
My Device: Bold 9700
My Carrier: Maxis Malaysia
Accepted Solution

Setting value in ObjectChoiceField

Hi!

I'm using ObjectChoiceField and been wondering is there any way we can use it to also include "hidden" value. Just like in html where we can always use <option value="0" >No email notification</option>.

public ObjectChoiceField(String label, Object[] choices, int initialIndex, long style)

Putting Object[] as value to be saved is OK, but that value must also be readable by human and it just wasting bb resource to store it for future retrieval.

Or we just stuck with it? Sorry, but I'm a newbie. :smileysad:
Please use plain text.
Developer
simon_hain
Posts: 15,953
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Setting value in ObjectChoiceField

you cannot use hidden values in an objectchoicefield. the field uses toString for the objects stored in it, you can either use strings or own objects that overwrite toString to provide some useful text.
----------------------------------------------------------
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
Please use plain text.
Regular Contributor
DingDang
Posts: 61
Registered: ‎03-28-2010
My Device: Bold 9700
My Carrier: Maxis Malaysia

Re: Setting value in ObjectChoiceField

Thank you sir. Do you have some sample of that code?

Please use plain text.
Developer
simon_hain
Posts: 15,953
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Setting value in ObjectChoiceField

you want a sample for a string? or a sample for overwriting toString?

----------------------------------------------------------
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
Please use plain text.
Regular Contributor
DingDang
Posts: 61
Registered: ‎03-28-2010
My Device: Bold 9700
My Carrier: Maxis Malaysia

Re: Setting value in ObjectChoiceField

*ashame*

 

Issit something like this :

 

ObjectChoiceField myChc = new ObjectChoiceField("Choices : ", myChcOb.value.tostring(), 0, ObjectChoiceField.FIELD_LEFT)

 

and if i wanna read the "hidden" value, i just get it like this :

 

selectedVal = myChc.getChoice(myChc.getSelectedIndex());

 

Now, how should i create myChcOb?

 

I know it is more like OOP subject rather than BB. :smileysad:

Please use plain text.
Developer
simon_hain
Posts: 15,953
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Setting value in ObjectChoiceField

you create the field with an array of objects.

 

your object could look like this:

 

public class Bean{

 

private String secret;

private String description;

 

public Bean(String description, String secret){

this.secret=secret;

this.description=description;

}

 

public String getSecret(){

return secret;

}

 

public String toString(){

return description;

}

 

}

 

now create an array of Bean objects and initialize your field with it:

ObjectChoiceField myChc = new ObjectChoiceField("Beans : ", beans, 0, ObjectChoiceField.FIELD_LEFT)

----------------------------------------------------------
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
Please use plain text.
Regular Contributor
DingDang
Posts: 61
Registered: ‎03-28-2010
My Device: Bold 9700
My Carrier: Maxis Malaysia

Re: Setting value in ObjectChoiceField

You have sent me to the right direction, sir. Thank you very much! :smileyhappy:

Please use plain text.