I have the following loop which creates a String which fits exactly in a screen, it creates a page so to speak.
for (int i = 0; i < totalLine; i++) {
temp = enterLine(mTextView, textToBeShown, i);
full = full + temp;
}
So after the iteration is done full holds one page.
What i want to do is create an outer iteration which allows me to create more than one page, the amount of pages to be created isn't defined. So the iteration needs to stop if there aren't more pages to be created.
I tried the following code but for some reason when calling a page Pages.get(1) it gives out the whole String not just the full / Page. For Example if i three strings have been added to the ArrayList Pages there will be three Strings in the ArrayList but all with the same value.
With some testing with the Log, i know that the first iteration is working well, and that full gives the expected values meaning in the first do iteration gives out the expected values to the full so does the second iteration etc..
do{
for (int i = 0; i < totalLine; i++) {
temp = enterLine(mTextView, textToBeShown, i);
if(temp.trim().length() == 0){
break;
}else{
full = full + temp;
}
}
Pages.add(full);
So the question is what am i doing wrong with the ArrayList and why isn't it working as I'm expecting.
Edit
This is the enterLine code: More Log's were used didn't feel the need the display them all.
public String enterLine(TextView mTextView, String textBeShown, int i){
String A;
int number = mTextView.getPaint().breakText(textToBeShown, 0, textToBeShown.length(),true,mTextView.getWidth(), null);
if(textToBeShown.substring(number-1,number) != " "){
number = textToBeShown.substring(0,number).lastIndexOf(" ");
Log.e("TAG1", "Found " + i);
}
A = (textToBeShown.substring(0, number) + "\n");
Log.e(TAG, textToBeShown.substring(0, number));
textToBeShown = textToBeShown.substring(number, textToBeShown.length());
return A;
}
enterLine, not sure what that is doing...enterLineworks correctly, altough it can be connected to it.fullto an empty value somewhere, no? You keep filling it. Would it be a good idea to reset it bewteendoandfor?whilefor thedo? Also, havefullbe aStringBuilder, not aString.