I am using the BlackBerry knowledge center tutorial “How To Format RichTextField” to set a format for my RichTextField.
I encountered some difficulty when formatting text like:
A I was walking in the street B suddenly I saw a flying dog
If I want to bold only the letters A & B I need to have their string indexes and length.
I created 2 arrays, one handles the indexes of the letters in the entire text and the second array handles the length of each letter index, for example: A (length 1), WC(length 2).
I tried to run it in a loop but it doesn’t work:
Font fonts[] = new Font[2];
int[] offset = new int[3];
byte[] attribute = new byte[3];
//Get three instances of the default font.
//On plain, one bold and one bold and italic.
fonts[0] = Font.getDefault();
fonts[1] = Font.getDefault().derive(Font.BOLD);
for (int i = 0; i<lettersLength; i++) {
offset[0] = letterIndexes[i]; //handles the indexes of the letters in the entire text
attribute[0] = 1;
offset[1] = letterLength[i]; //handles each letter index
}
Sorry not nicer code, but hope it helps.