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
New Developer
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Regarding EditField and ChoiceField

Hi Friends

 

I have 5 editFields and one ObjetctChoiceField. I want to change the size of EditField as per the needs. Eg. Name, price, city, state,MLS no.

All the Field are differ in width.

How can I do it?

 

Regards

Nimesh

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

Re: Regarding EditField and ChoiceField

objectchoicefield uses the whole width by default, placing the label of the left, the choices on the right side. if there is not enough space it concumes a second line.
editfields have a similar behaviour.
you can change the default layout by overwriting getpreferredwitdth in the field class or using a custom layout manager.
----------------------------------------------------------
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
New Developer
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Regarding EditField and ChoiceField

I am not getting you. Because I don't know about how to add customfield so If you have any sample code plz provide it.

I hav already refer this but I can't get it.

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/... 

 

 

 

Thanks

Nimesh

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

Re: Regarding EditField and ChoiceField

Could you please restate your requirement, I'm not clear on which widths are causing you a problem.  It might be easier if you did a little picture of what you are trying to achieve.
New Developer
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Sure Peter,

I have 5 editField and 1 ObjectChoiceField.

1st EditField Contains Name Means It should have more space, let it will take 20 characters, but as we add the Field it will cover whole the screen width which I dont want.

And 2nd EditFiled contains price it consider maximum 7 characters. So it's width is lesser then the first one.

 

Simillarly for other EditField.

Same for ObjectChoiceField. 

 

( In addition is it possible to have the field which is shown in google search engine, even if the Input is large the textbox width remains the same, while in bb device it takes new line.)

 

 

Thanks

Nimesh

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Regarding EditField and ChoiceField

[ Edited ]
For Displaying the different width you can override layout method, given is the sample code. Depending on the number of chars you fixed you can set the width of the field.

BasicEditField bef1 = new BasicEditField("Test1: ","")
{
private int X = getFont().getAdvance(getLabel());
private int W = Display.getWidth() - X - 4;

public int getPreferredHeight()
{
return 30;
}

public int getPreferredWidth()
{
return 100;
}

public void layout(int width, int height)
{
setExtent(width, getPreferredHeight());
super.layout(width, getPreferredHeight());
}

public void paint(Graphics g)
{
g.setColor(0x000000);
g.drawRect(X, 0, W, 25);
super.paint(g);
}
};
add(bef1);

 

About your question, You can use the HorizontalFieldManager, your text will scroll horizontally. Given is the sample code.

 

HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL);
BasicEditField bef = new BasicEditField("Test: ","");
hfm.add(bef);
add(hfm);

 

PS: Above code snippets copied from posts in this forum.
Message Edited by BBDeveloper on 03-10-2009 11:10 AM

Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Thanks for Reply

 

But getting same problem just modification is it will show the rectangle.

But still it will take whole screen for the input.

 

And if you still don't getting me plz tell me how to send the image.

 

Thanks

Nimesh

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Set the rectangle width accoring to the number of chars you going to enter and restrict teh number of chars to be entered using the constructor by setting the max chars allowed for the field.

Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Thanks

I have tried this.

My problem is that if I can use that also then also the it will take the whole width and I have to add one Button which is not appear on the screen and I don't want Horizontal Scroll for this.

i.e.

Test1 : Hi BBDeveloper  Button1

 

Regards,

Nimesh

 

 

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Is it something like this.

HorizontalFieldManager hfm = new HorizontalFieldManager() { protected void sublayout(int width, int height) { Field field; int numberOfFields = getFieldCount(); int x = 0; int y = 0; for (int i = 0;i < numberOfFields;i++) { field = getField(i); setPositionChild(field,x,y); layoutChild(field, width, height); x += 280; } width=450; height=50; setExtent(width, height); } }; BasicEditField bef1 = new BasicEditField("Test1: ","Hi! BBDeveloper",15,Field.FOCUSABLE); hfm.add(bef1); ButtonField bf = new ButtonField("Button"); hfm.add(bf); add(hfm);

 


 

 


Use Search. "Accept Solution" If the problem is resolved.