Note that there are some explanatory texts on larger screens.

plurals
  1. POArrayList not working as expected in do..while loop
    primarykey
    data
    text
    <p>I have the following loop which creates a String which fits exactly in a screen, it creates a page so to speak.</p> <pre><code> for (int i = 0; i &lt; totalLine; i++) { temp = enterLine(mTextView, textToBeShown, i); full = full + temp; } </code></pre> <p>So after the iteration is done <code>full</code> holds one page.</p> <p>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.</p> <p>I tried the following code but for some reason when calling a page <code>Pages.get(1)</code> it gives out the whole String not just the <code>full</code> / Page. For Example if i three strings have been added to the <code>ArrayList</code> <strong>Pages</strong> there will be three Strings in the <code>ArrayList</code> but all with the same value.</p> <p>With some testing with the <code>Log</code>, i know that the first iteration is working well, and that <code>full</code> gives the expected values meaning in the first <code>do</code> iteration gives out the expected values to the <code>full</code> so does the second iteration etc..</p> <pre><code> do{ for (int i = 0; i &lt; totalLine; i++) { temp = enterLine(mTextView, textToBeShown, i); if(temp.trim().length() == 0){ break; }else{ full = full + temp; } } Pages.add(full); </code></pre> <p>So the question is what am i doing wrong with the <code>ArrayList</code> and why isn't it working as I'm expecting.</p> <p><strong>Edit</strong></p> <p>This is the <code>enterLine</code> code: More <code>Log</code>'s were used didn't feel the need the display them all.</p> <pre><code>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; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload