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
Posts: 192
Registered: ‎01-12-2010
My Device: Bold
My Carrier: ZAIN

objectchoicefield selected index

Dear Guys,

i have two objectchoice field in my screen

and i am using the below code to get the selected index changed value

final Object obSize = pickSize.getChoice(pickSize.getSelectedIndex());
		strFontSize = obSize.toString();
    	fontSize = Integer.parseInt(strFontSize);

 

it works well for the frist objectchoicefield but for the second one it always gives me the first value

 

 

any ideas

i tried following this thread but i couldnt find my answer

http://supportforums.blackberry.com/t5/Java-Development/objectchoicefield-getselectedindex/td-p/5828...

 

rgds

Nadir Firfire

 

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

Re: objectchoicefield selected index

can you show the whole (relevant part of the) code? maybe a faulty reference?

----------------------------------------------------------
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: 950
Registered: ‎06-22-2010
My Device: 9550

Re: objectchoicefield selected index

Check Listener of the ObjectField you are adding or not.

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

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

Developer
Posts: 192
Registered: ‎01-12-2010
My Device: Bold
My Carrier: ZAIN

Re: objectchoicefield selected index

String[] iFontSize = {"10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"};

pickSize= new ObjectChoiceField (" Select Font Size  :", iFontSize,0,Field.FIELD_LEFT);


final Object obSize = pickSize.getChoice(pickSize.getSelectedIndex());
strFontSize = obSize.toString();
fontSize = Integer.parseInt(strFontSize);
//Listener for testing only
pickSize.setChangeListener(new FieldChangeListener(){

			public void fieldChanged(Field field, int context) {
				Dialog.alert("Real Object Value:" + obSize.toString());
				Dialog.alert(String.valueOf(fontSize));
				
			}});
    	

 this is only code i have to do the stuff

 

 

rgds

Nadir Firfire

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

Re: objectchoicefield selected index

you have to move your selection code into the fieldchangelistener.

the way you implemented it it does never change.

----------------------------------------------------------
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: 192
Registered: ‎01-12-2010
My Device: Bold
My Carrier: ZAIN

Re: objectchoicefield selected index

Dear Simon,

did it but no luck

 

rgds

Nadir Firfire

 

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

Re: objectchoicefield selected index

how about posting the changed 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
Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: objectchoicefield selected index

 

String[] iFontSize = {"10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"};

pickSize= new ObjectChoiceField (" Select Font Size  :", iFontSize,0,Field.FIELD_LEFT); 
//Listener for testing only pickSize.setChangeListener(new FieldChangeListener(){ public void fieldChanged(Field field, int context) { Dialog.alert("Real Object Value:" + obSize.toString()); Dialog.alert(String.valueOf(fontSize)); }});

strFontSize= pickSize.getChoice(pickSize.getSelectedIndex()); 
fontSize = Integer.parseInt(strFontSize);

I think This should work.

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

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

 

 

Developer
Posts: 192
Registered: ‎01-12-2010
My Device: Bold
My Carrier: ZAIN

Re: objectchoicefield selected index

no luck till now

 

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

Re: objectchoicefield selected index

put the code INTO the fieldchangelistener.

not above it, now below it.

 

blackberry is maybe not the best platform for the early steps.

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