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

Re: Regarding EditField and ChoiceField

[ Edited ]

Thanks,

 

If i dont want to ristrict for characters then What to do?

Because as I have remove the constructor of "maximumchar" the input is going behind the Button.

And second thing is there any way to as the input is larger then the width of the field it will not go to second line but goes inside like we are using inweb pages or software.

 

And for the objectchoicefield is it the same way?

 

Thanks

Nimesh

Message Edited by nimesh on 03-10-2009 04:48 AM
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Hi,

 

I think no such API is avialble , which will you in implementing google like textField, you have to implement that on your

own.

 

You can fix the size of you textField say 20 characters , when limit is reached just remove one character from starting

and append latest character in the end.

 

This way you can produce the desired effect.

 

I will try to post the code snippet soon.

 

Plese let me know if you find any other solution for this.

 

 

 

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
New Developer
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Regarding EditField and ChoiceField

[ Edited ]

Thanks Rajat for your suggestion

If you can provide me the code for refference, that will be good for me.

I am trying for other alternative also.

 

Regards,

Nimesh

Message Edited by nimesh on 03-10-2009 06:45 AM
New Developer
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Hi Rajat,

 

 

Waiting for your code snippet, its urgent or do you have any other way by which I can reduce the text box size according to my wish.

 

 

Thank you in advance,

Nimesh.

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

Re: Regarding EditField and ChoiceField

sometimes you have to do stuff yourself. it is hard, it is sometimes not easy, but you have to face it.
----------------------------------------------------------
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
Highlighted
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Hi Nimesh,

 

Sorry I was out of town for 3 days thats why not able to answer your query.

 

Below is code , hope this code will help you out in what you want to implement.

 

Just add few validations according to you.

 

class TreeComponentScreen extends MainScreen implements KeyListener{ StringBuffer dataString = new StringBuffer(); BasicEditField txtInput = new BasicEditField(); TreeComponentScreen() { super(DEFAULT_MENU | DEFAULT_CLOSE); //addKeyListener(this); drawComponent(); } public void drawComponent(){ add(txtInput); } public boolean keyChar(char key, int status, int time) { return true; } public boolean keyDown(int keycode,int time){ if(txtInput.getText().length()<10 && Keypad.key(keycode)!=8){ txtInput.setText(txtInput.getText() + returnChar(Keypad.key(keycode))); }else if(Keypad.key(keycode)==8){ if(txtInput.getText().trim().length()!=0 && txtInput.getCursorPosition()>0){ //txtInput.setText(txtInput.getText().substring(0,txtInput.getText().length()-1)); int position = txtInput.getCursorPosition(); if(position<txtInput.getText().length()){ String text = txtInput.getText(); String part1 = text.substring(0,position-1); String part2 = text.substring(position,text.length()); txtInput.setText(part1 + part2); }else{ txtInput.setText(txtInput.getText().substring(0,txtInput.getText().length()-1)); } txtInput.setCursorPosition(position-1); } }else{ StringBuffer SBdata = new StringBuffer(txtInput.getText()); SBdata.deleteCharAt(0); txtInput.setText(SBdata.toString() + returnChar(Keypad.key(keycode))); } return true; } public char returnChar(int x){ if(x==65){ return 'A'; }else if(x==66){ return 'B'; }else if(x==67){ return 'C'; }else if(x==68){ return 'D'; }else if(x==69){ return 'E'; }else if(x==70){ return 'F'; }else if(x==71){ return 'G'; }else if(x==72){ return 'H'; }else if(x==73){ return 'I'; }else if(x==74){ return 'J'; }else if(x==75){ return 'K'; }else if(x==76){ return 'L'; }else if(x==77){ return 'M'; }else if(x==78){ return 'N'; }else if(x==79){ return 'O'; }else if(x==80){ return 'P'; }else if(x==81){ return 'Q'; }else if(x==82){ return 'R'; } return '0'; } public boolean keyUp(int keycode,int time){ return true; } public boolean keyStatus(int keycode,int time){ return false; } public boolean keyRepeat(int keycode,int time){ return false; } }

 

Just add rest of the characters also after character 'R'.

 

Hope this will help you.

Please let me know if this helped you or not.

 

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Regarding EditField and ChoiceField

I would be wary of using keyDown() for any code going on a SureType device, like the Storm, I suspect using a Field Change Listener instead.

 

Also I think the:

public char returnChar(int x){..}

routine can be coded much more simply, for example

 

public char returnChar(int x){

if ( x >= 'A' && x <= 'Z' ) {

return (char) x;

}

return '0';

}

 

Finally, having reviewed this again, I am still not clear what is required.  It seems you want to do two things, both of which have been explained by BBDeveloper:

a) Restrict the number of characters in the Field - BBDeveloper suggests using the constructor 'maximum chars' parameter, or you can use the associated set method.

b) Restrict the size taken up by the Field on the Screen - BBDeveloper suggests overriding layout.

 

Can you try to explain again what is wrong with these suggestions?

 

 

Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Hi,

 

Yes Peter you are right returnChar() routine can be written in more simple way.

 

 I have just given Nimesh an idea about it.

 

Secondly I think what Nimesh wants is implementing a textfield which can contain say 20 characters at a time but if 21 character is pressed it will delete 1 character in textfield and append this character in the textfield , but still if you call getText() of textField you will get all 21 characters.

 

Something similar which we can see on google page when we enter text in its search field text simply shifts towards left side.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
New Developer
Posts: 84
Registered: ‎01-28-2009
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Hi guys, reallly I am very thankfull for all your support.

 

My actul problem is that to resize the EditField, there should be no restriction in that. I have just given example for understanding purpose .

 

Just run the Below code U can see that the EditField Takes the whole width of the screen as I border it :-

 

public class FinaScreen extends MainScreen { VerticalFieldManager _manager; public FinaScreen() { _manager = (VerticalFieldManager)getMainManager(); Background bg = BackgroundFactory.createSolidBackground(Color.LIGHTBLUE); _manager.setBackground(bg); LabelField lb1 = new LabelField(" ENTER"); 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 += 100; } width=450; height=50; setExtent(width, height); } }; hfm.add(lb1); EditField bef1 = new EditField(Field.FOCUSABLE); editBordering(bef1); hfm.add(bef1); ButtonField bf = new ButtonField("Button"); hfm.add(bf); add(hfm); }

 

 

And if I override the paint() then also the same problem occurs.

 

 

Regards,

Nimesh

 

Developer
Posts: 57
Registered: ‎01-29-2009
My Device: Not Specified

Re: Regarding EditField and ChoiceField

Hi Nimesh,

I have seen all the post. According to me BBDeveloper is right for resize the editfield.

I can do some help in this.

Just set the width in the sublayout for your size of the editfield. Using HorizontalFieldManager you can set the button also.

 

I found your another question that input text like google. I dont know about that. But surely it is, Because I have seen it in BB simulator browser itself.

I am working on it If any thing found, I will give you. 

 

Regards,

Vaikunth