For example, I have a very long text and I have a text view at the center of the screen with the below properties.
<TextView
android:id="@+id/conftextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|left"
android:minHeight="350dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:textColor="#FFFFFF" />
Now, I created an OnClick Listener so that for each tap the text changes and starts from where it ended last.
I have few constraints here the text view can be either square or height < width but not height > width. So, I figured that having exactly 22 lines per view solves my problem.
But, how can I split the content into exactly 22 lines I tried to do with word split and considering 200 words per view but if there are many lines breaks this logic is failing.
/*
Process and split text into 200 worded parts
*/
protected TreeMap<Integer,String> processText(String inputText, int maxWords){
TreeMap<Integer,String> multiPageText= new TreeMap<Integer,String>();
String words[] = inputText.split(" ");
int wordCount = words.length;
int keyCount = (int) Math.ceil(wordCount/(double)maxWords);
for (int i = 0; i < keyCount;i++){
StringBuilder sb = new StringBuilder();
for (int j=i*maxWords;j<((i+1)*maxWords < wordCount ? (i+1)*maxWords : wordCount);j++){
sb.append(words[j]);
sb.append(" ");
}
multiPageText.put(i, sb.toString().trim());
}
// System.out.println(keyCount);
return multiPageText;
}
Using the Map returned above I am handling different pages but I am looking for a way where I can split the text exactly at 22 lines regardless of how many line breaks were there or how long the text is.
Any leads would be appreciated. TIA.