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: 9
Registered: ‎12-19-2011
My Device: 9300
My Carrier: MTN

how can i retrieve a specific line of text from a multiline BasicEditField

please help, still reletively new in this development. how can i retrieve a specific line of text from a multiline BasicEditField. for example we have these lines of text in a BasicEditField:

 

this is the first line
this is the second line
and this is the last line

 

is there a way i can retrive a specific line of text here, please help with a code if you can?

 

thanks for help

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

Re: how can I retrieve a specific line of text from a multiline BasicEditField

Assuming the lines displayed have been auto-wrapped, there is not way to do this.  You could go through using Font.getAdvance(...) and try to second guess where the Field may have wrapped.

 

If the lines are split using Carriage Return/Line Feed type terminators, then you could look for these in the String.  YOu would have to look for these in the case of auto wrapping too. 

 

Sorry, this might be a difficult thing to do.

 

Have you thought about asking the user to Select the characters?

New Developer
Posts: 9
Registered: ‎12-19-2011
My Device: 9300
My Carrier: MTN

Re: how can I retrieve a specific line of text from a multiline BasicEditField

thanks alot Peter

 

may you please assist with a code to search for Carriage Return/Line Feed type terminators.

 

the user's input is not needed in this case.

 

regards

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

Re: how can I retrieve a specific line of text from a multiline BasicEditField

Something like this....

 

String testString = <inputField>.gettext();

Vector linesFound = new Vector();

int nextNewLine = testString .indexof("\n");

while ( nextNewLine >= 0 ) {

if ( nextNewLine = 0 ) {

// line with no characters

linesFound.add("");

} else {

linesFound.add(testString.substring(0,nextNewLine);

}

// Now remove the line we have just extracted

if ( testString.length() > nextNewLine ) {

testString = testString.substring(nextNewLine+1);

} else {

testString = "";

}

}

linesFound.add(testString);

 

I just coded this.  There are likely to be bugs in here and it won't compile, but you get the idea...

New Developer
Posts: 9
Registered: ‎12-19-2011
My Device: 9300
My Carrier: MTN

Re: how can I retrieve a specific line of text from a multiline BasicEditField

thanks Peter.

 

i will try it.

 

regards

Highlighted
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: how can I retrieve a specific line of text from a multiline BasicEditField

while( (_c = _dis.read()) != -1 ){
Vector SSV1 = new Vector();
//To Remove the particular Elements
SSV1.removeElementAt((char)_c);
}

-Fight with BB10