Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build an Interactive Story App (Retired) Finishing the User Interface Creating the Story Layout

Javier Diaz
Javier Diaz
1,740 Points

TextView

Can we write a large text in a TextView? is there a limit of words? Thank you

2 Answers

Yes you can write a large text. I am not sure how it will look like in your app but it is possible. You can set limit of words but I haven't heard of there being a limit to that by default. I suggest you have a look at this as well.

Harry James
Harry James
14,780 Points

Well... there is kind of a catch...

Another user had an issue where they were trying to write a large amount of text in a TextView and, this caused an error for them. Unfortunately, the fixes are not easy and instead require you to "stream" the characters (So, appending a character to the TextView each time instead of just attaching a block of text).

The thing is... if you write the string in XML format (Using android:text), it works fine. But, if you write it in Java as a string (String myString = "Really long string..."; ), you get an error.


But, just now, I managed to think of a solution without the really difficult need to stream characters! And I tested it :)

I noticed that it works in XML format so, you can simply write your String in Strings.xml in your values directory and, hey presto! You can then use

TextView textView = (TextView) findViewById(R.id.textView);
textView.setMovementMethod(new ScrollingMovementMethod());

String longText = (String) getText(R.string.longText);

textView.setText(longText);

in your Java code and you're all sorted!

In case you were wondering, I'm using the setMovementMethod here because it allows you to scroll a page with long text :)

Hope it helps!