TextView doesn't show text - java

I'm developing an ebook app for Android. when the text length given in string.xml is very large (around 500 words) it is not shown in the text view.
It took a while for me to figure this out. I have two text views and one is working propoerly as it is a small paragragh with 100 words but the secound TextView is larger and when the event is triggered it shows an empty screen.
Any char limitation in TextView?? wot would be the alternative?? Please help me.
Thanks in advance.

TextView doesn't sound like the correct component for your use. I would imagine you would get much better results using WebView.
You can define your content in HTML files instead of putting that much text into strings.xml.

Related

How can I predict the total number of characters can fit inside a textView?

I want to make a multipage ebook reader using viewPager. suppose I have a full screen textView inside a viewPager. Now I want to insert the exact number of text characters which will be fit inside the textView. You might be observed this strategy in Moon reader, fb reader. I can handle all the coding part except calculating the number of caracters can fit inside the textView. Any suggestion will be appreciated.

How to format xml and java code as text inside TextView

I am creating an Android Tutorial Application. I am planning to use Tabs to display the java and the xml code used for that topic.
I thought of using TextView and applying the Java and XML code as text to it.
However I am failing to format the Java code, plus I am not able to add xml as text at all as it has tags which are not supported.
Below are snaps from another App and the desired output is what I am looking for.
Any help or suggestions are welcomed.
You could display your Code in your TextView with HTML and style/format it with CSS.
Try this,
Suppose you have HTML code like this
<h2>Title</h2><br>
<p>description here</p>
Then in android you can use below code
TextView tvTrial=(TextView)findViewById(R.id.tvTrial);
String html="<h2>Title</h2><br> <p>description here</p>";
tvTrial.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Now any thing you want to display in you view you can store it the string and set it.

Android - Formatting text (textView vs button)

I'll try to keep it simple, but it's two part.
In my Android app, I have a textview anf 4 buttons (question and 4 answers). I'm attempting to utilize the html <sub>subscript</sub> and <sup>superscript</sup>. It's working on the textivew (ie. the text is formatted the way I want it to be), but when I try to do the same thing on the buttons in the exact same way, it doesn't format them. X2 just becomes "X2" without superscript.
Why is this the case and how can I get it to work on the buttons like it works on the textview?
If it helps, I noticed something. If I pull the same string to the textview and to the buttons (keep in mind I'm pulling the strings from a variable set in a java structure I made... questions/answers I coded into arrays), the textview will read "Question # 1" and the button will read "QUESTION # 1". So, somehow the button is formatting the text and I wasn't aware of that. Could this be the reason the <sub> html code isn't working on the buttons? What's causing this and how can I fix it?
Thank you.

Converting BB code to HTML for TextView

I'm trying to convert BB code to HTML in Java for an Android project. An example of the text in which the bb code is embedded looks like this:
[b]This[/b] is some [url="http://www.example.com"]example[/url] text
to display my problem.
There also might be several paragraphs [i]of[/i] text and normal URLs http://www.example.com.
What it needs to look like in the TextView:
This is some example text to display my problem.
There also might be several paragraphs of text and normal URLs http://www.example.com.
Unfortunatly I don't have any code to show you since i don't know how to go about doing this. The only thing i can come up with now is making alot of regular expressions but i´m not sure if that would be the best solution.
Eventually this will all be displayed in an Android TextView.
Any help is appreciated!
There are some java BB-code libraries out there. Check this question for information on them.

Scrolling TextView in a ScrollView to a specific substring of text

For starters, I'm a C++/Qt Developer jumping into Android/Java development, so please don't assume I know anything. :) So, I have an application with a TextView contained with in a ScrollView. The text contained in the TextView is the results of a web query from my web server application. Depending on the query, the text can be pretty long. I want to implement a search feature on the text where the user enters some text string to search for, and if the text string is found, the ScrollView will scroll the TextView to ensure the entered substring is visible, and I want the text highlighted. I think I know how to highlight the text substring, I know how to tell the ScrollView to scroll to a specific line number in the TextView, but for the life of me, I can't figure out how to find out what line number to scroll to to guarantee my substring is visible. Ie, I want to query the text view to give me the line number that the substring first occurs at. Eventually, I want to also implement a find next that goes to the next occurrence of the substring. Kind of like the Find feature in Firefox. Any assistance is greatly appreciated. Thanks in advance.
You need to find the position of the substring in the text yourself, e.g. with String.indexOf(). Once you know that position, you can look up the correct line in the TextView using the Layout.getLineForOffset() function:
int offset=myString.indexOf("search string");
int line = myTextView.getLayout().getLineForOffset(offset);

Categories