I saw this topic that tells me how to display HTML text in a TextView in Java. For example, if my TextView has "<small>Hello</small>" as its text and I used the code in that topic, I would see a small "Hello" in my TextView.
Now I want to reverse this. I want to get the HTML code of the TextView that I have enabled HTML format, i.e., I want to get "<small>Hello!</small>". Is there a way to do this?
I have tried tv.getText() (tv is the name of the TextView), but it instead returned "Hello", not as I had expected.
Related
In essence, I am trying to replace the text that a TextView element contains with a string obtained from scanning a QR code, to test if the scanner actually works
You should be able to edit the text with the setText function
public final void setText (CharSequence text)
https://developer.android.com/reference/android/widget/TextView#setText(java.lang.CharSequence)
and here's a really nice article if that doesn't work as expected (debugging you may find that the TextView has the text you want, but is not displayed on the screen yet):
https://tekeye.uk/android/examples/ui/android-app-text-not-updating
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.
Im making a Notepad app, and I've got some problem with HTML converting.
In my notepad app user is able to format text via Spannable object.
I need to convert Spannable object to String when I'm putting it into DB Table via Html.toHtml() method.
When I'm trying to convert String back into Spannable via Html.fromHtml() method it ignores all tags that are using quotation marks in it.
For example:
I've got Spannable converted to Html that is able to change text size and it looks like this:
"<p dir="ltr"><font size ="6">HERE IS TEXT</font><p>\n"
After converting:
(Sorry for image, Stackoverflow were apllying my HTML code here, lol)
It works fine when im using tags without quotation marks like:
<p dir="ltr"><u>HERE IS TEXT</u></p>\n"
Do u know any solution for that or I need another way to serialize my Spannable object to String to get it into my SQLite DB?
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.
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.