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
naveensh
Posts: 51
Registered: ‎09-18-2008
My Device: Not Specified
Accepted Solution

when we select the radiobutton it should show the choice dropdown...

Hello

 

 

Can u pls help me how to get dropdown list option when we select the radiobutton in the same screen ,

when we deselect, it should hide the dropdown on the screen with out any focus...

 

Thanks in Advance.... 

 

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

Re: when we select the radiobutton it should show the choice dropdown...

This is not actually that hard to do.  The principles are as follows:

 

a) Use a change Listener to detect when the state of the radio button changes

b) In the change Listener, if the button has been set on, then add the dropdown to the screen, just using the usual Screen.add(dropdown)

c) In the change Listener, when the button is set off, delete the dropdown, again using the usual Screen.delete(dropdown)

 

No doubt you will want to add the dropdown in a particular place, presumably immediately after the radiobutton.  Then you have two options

 

1) Remember what 'index' into the Screen you want to place the drop down, and use the

Screen.insert(..) method to place the dropdown at that position.

You can find out the index by doing something like this

Screen.add(radiobutton)

insertIndex = Screen.getFieldCount();

 

2) Add a manager where you want to place the dropdown, then you just add and delete from that Manager

for example:

VerticalFieldManager vfm = new VerticalFieldManager();

... 

Screen.add(radiobutton);

Screen.add(vfm);

..

Then, in your Change Listener, you need to use one of the following

vfm.add(dropdown); // add it when radio button is checked

vfm.delete(dropdown); // delete it

 

I hope this all makes sense.  If not, ask me to clarify....

 

Developer
naveensh
Posts: 51
Registered: ‎09-18-2008
My Device: Not Specified

Re: when we select the radiobutton it should show the choice dropdown...

 

 

// I used the radiobutton like this. 

 

 auto  = new RadioButtonField("Auto",rgrp,true);

 

 

//I am using objectChoiceField for dropdown..

 

String choicestrs[] = {"Hoy", "Dy", "Wly","Mly"};
choice = new ObjectChoiceField("choices", choicestrs, 0, ObjectChoiceField.FOCUSABLE);

 

// i set the margin just below the my radiobutton. 

 

 choice.setMargin(-120,-120,-125,-125);

 

 when the radio button is checked the dropdown should get a focus and it should the options in it.if the radio is not checked it should disable the dropdown without any focus.

 

 Mainly i need to synchronise with the radio button and objectchoice field..for check and uncheck.

 

 if u have any code pls send me it will be helpful for me....

 

 

 

Thanks in Advance..

 

 

 

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

Re: when we select the radiobutton it should show the choice dropdown...

[ Edited ]

Sorry you have lost me.  How does the setMargin help in this case.  Actually to be honest, I'm not even sure what setMargin does.  What level of JDE are you using?

 

I might have got your requirement wrong.  I think you want to have a screen with radio button in it.  Then if the user checks the radio button, a drop list appears (let us say the drop list appears immediately below the radio button).  When the radio button is unchecked, the drop list is removed from the screen.  Is this correct?

 

If what I have asked is correct, the first thing you must add is the ChangeListener.  You will need to add a change listener so that you get notified when the state of the radio button is changed.  You will find information about this, including some sample code in the Developer Guide.  In the 4.5 manual, it is on page 31, in a section called "Listen for field property changes".

 

Then you need to add and delete your dropdown.  Your screen starts off without the dropdown, then when the radio button is checked (which you will detect in your ChangeListener), you can add it to your Screen, and so it will appear.  When the radio button is checked off (again detected in the ChangeListner) the dropdown is deleted from the screen, so will disappear.  Adding and deleting is easy - you must do an add already to have seen your radio button, delete is just the reverse!  So you just need to get your ChangeListener working.  .

 

I do have code that does this, but I think it is better that you develop this yourself and so understood the concepts.

Message Edited by peter_strange on 09-18-2008 05:04 PM
Message Edited by peter_strange on 09-18-2008 05:06 PM
Developer
naveensh
Posts: 51
Registered: ‎09-18-2008
My Device: Not Specified

Re: when we select the radiobutton it should show the choice dropdown...

u r Correct.

 

 

Acutally we r working on popupscreen with transperancy.

 

I am using the 4.3 its is supporting for setmargin(4.5 doesnt).

 

I Gone  through the doc 4.5 finally i got the result.

 

I need to set the dropdown just below the dropdown how can i without any hardcode...pls let me know..

now iam using setmargin( hardcode); 

 

If u have any tips which can help me in programing skills pls reffer me . 

I wil get backto u for next ........................

 

Thank u for ur way of Guidence...

 

 

 

 

 

 

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

Re: when we select the radiobutton it should show the choice dropdown...

First tip I would offer, is to suggest that you don't use text speak in these posts.  I personally find it more difficult to read, and I wonder what it is like for people who are not so comfortable in English.

 

I can not find setMargin in PopupScreen either, in the 4.3 doc.  Can you confirm which class you are using it against?

 

But your real question seems to be this:

You have managed, with a Change Listener, to add and delete the dropdown.  Now you want to position it immediately after the radiobutton.

 

I covered this in my original post.  Rather than confuse you with my second method which involved an extra Manager, for now let us use the first.

 

When Fields are added to a manager, they go in a list, which we can think of as an array with an index.  So the first one you add is index 0, the second one is index 1.  You can ask the Manager how many Fields are in its list using getFieldCount().  So you can do the following in a PopupScreen (which extends Manager, so has all the Manager methods).

 

int aFieldIndex = this.getFieldCount();

this.add(aField);

 

Now aFieldIndex is the index to aField in this Screen.

 

If I wanted to add another Field, immediately after aField, then I could do the following:

 

insert(anotherField, aFieldIndex);

 

With this anotherField will appear immediately after aField.

 

Hope this makes sense and explains what you need to know.