0

I am currently building an Book-App (sort of). So there are a lot of Strings, and the User can choose from which line he wants to start reading. So e.g there are 200 Strings in a String Array for Chapter one. And the User wants to start reading at Line 20(because he read the Lines before already). How can I display all the Strings from 20-200? I have got:

    Resources res = getResources();
    String[] Book= res.getStringArray(R.array.ChapterOne);
    TextView ChapterOne= (TextView) findViewById(R.id.Text);
    SuraAlFateha.setText(Book[20]);

But This just diplays the Line 20. But I want it to Display All the Lines following from 20 (20-200). How can I do this? Thank you.

2 Answers 2

1

When you set the text you need to set all the text at once, like:

String resultString = '';

for ( int i = 20; i < Book.length; i++ )
    resultString = resultString + "\n" + Book[i];

SuraAlFateha.setText( resultString.substring( 1 ) );

or something similar.

You should however calculate how much space you need and reserve it before starting the string appending or else your runtime and memory usage might get sky high.

Sign up to request clarification or add additional context in comments.

Comments

1

Book[20] will simply give you the 20th element of the array, if you wish to get text for 20 through the end, you'll need to join the range of elements into a string.

You can use text and array utils to make this easy.

String joinedLines = TextUtils.join("\n", java.utils.Arrays.copyOfRange(Book, 20, Book.length));
SuraAlFateha.setText(joinedLines);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.