BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   Custom Radio Buttons (http://www.blackberryforums.com/developer-forum/127437-custom-radio-buttons.html)

baran_khan 04-29-2008 02:44 AM

Custom Radio Buttons
 
Hi,

Can anyone please tell me if we can customize a radio button. I need two thigns to be done in here

1. Change the radio button image. The color of the circle when selected.
2. Display the radio button from right to left. I need radio buttons to be displayed on right side with text on the left.

Thanks in advance!!!

Ivanov 04-29-2008 03:45 AM

You will have to create your own field or extend the existing RadioFieldButton and override it's layout and paint functions.

Maybe this article helps you to start:
How To - Create custom fields

baran_khan 04-29-2008 03:47 AM

Hello Ivanov,

Thanks for ur reply...thats what I have been trying to achieve here..but the problem that I am facing is ..i have customized all the elements like, layout, labels, buttons everything...but when i try the same for the radio buttons...i get the error...do u have any idea about how we can do it???

Hope to hear from you soon

Ivanov 04-29-2008 03:51 AM

Never tried to extend the RadioFieldButton, but it should work if you do all the painting by yourself without calling paint() of the super class.
Do you have some code for us?

baran_khan 04-29-2008 04:02 AM

I can give the code for buttons, field managers etc. but not for radio button...not able to create one :(

Ivanov 04-29-2008 04:12 AM

You mentioned that you get en error, which is it?

baran_khan 04-29-2008 04:17 AM

Ohh...m sorry that was about tryin to align the radio button to right side and put a lebel field with the text on the left side...I was thinking about a custom layout with fixed height and varying height to put the labelfield with the text and put the radio button on the right side. The problem here I faced was that the setExtent() method require both height and width and I only want width to be fixed to the 80% of the screen and height should depend on the content.

If i dont use setExtend, then it uses the whole screen...That was the issue....
Either we get the radio button customized or else we can manage the fieldmanager to have fixed width and varying height...any of them will work...

Ivanov 04-29-2008 04:43 AM

can you post the code for the manager?

baran_khan 04-29-2008 04:45 AM

Here it is...all we have to do is to provide the height and width of the vertical manager...

package customElements;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.VerticalFieldManag er;

public class CustomVerticalLayout extends VerticalFieldManager
{
public CustomVerticalLayout()
{
super(VERTICAL_SCROLL|VERTICAL_SCROLLBAR);
}

int Width = 318;
int h= 120;
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Width, h);
setExtent(Width, h);//This is where i want only the width but not the height...
}

public int getPreferredWidth()
{
return Width;
}

public int getPreferredHeight()
{
return h;
}
}

The height should remain incremental...which m not able to do right now...

Ivanov 04-29-2008 05:13 AM

It is still difficult for me to understand what you are trying to achieve. If your manager should be scrollable, it needs a fixed size on the visible screen.
Can you give more information about the behaviour of your user interface?

to calculate the height of your manager depending on the fields in it you can try this:

PHP Code:

    protected void sublayout(int maxWidthint maxHeight)
    {
        
super.sublayout(maxWidthmaxHeight);
        
        
int height 0;
        
int fieldcount getFieldCount();
        for (
int i=0fieldcounti++)
        {
            
height += getField(i).getHeight();
        }
        
setExtent(Width height);
    } 


baran_khan 04-29-2008 05:17 AM

OK..lets take it this way....I want half of the screen width to be used to display a label with multiple lines of text i.e. to accomodate the content the height should be increased but width should remain teh same, Now the point here is the custom layout can have a fixed width and height. But I dont know how many lines the text will occupy and hence cannot provide the height.

Ivanov 04-29-2008 05:45 AM

this should work.

PHP Code:

    protected void sublayout(int maxWidthint maxHeight)
    {
        
super.sublayout(maxWidthmaxHeight);
        
        
int height 0;
        
int fieldcount getFieldCount();
        for (
int i=0fieldcounti++)
        {
            
height += getField(i).getHeight();
        }
        
setExtent(maxWidth 2height);
    } 

however the height of the labelfield added to this manager was restricted to the half of the screens resolution during my tests. I'm not sure if it's a bug or RIM's restriction in their implementation of the LabelField. So I guess you have to implement your own LabelField too.

Also take a look at the TextBox field from the developer journal:
BlackBerry - BlackBerry | Wireless Handheld Devices, Software & Services from Research In Motion (RIM)

baran_khan 04-29-2008 06:00 AM

YOU ROCK MY FRIEND......this took the toll on me...you just got it right..i used my already existing custom text field for the content and it did exactly what I wanted to do. Now i ll do the same using labelfield.

I ll bother you again should i face any trouble......;-)

Thanks a million for ur help!!!!!!!!(y)


All times are GMT -5. The time now is 02:16 AM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.