I have textview in my app. I have a string which I set in the textview.
The string is HTML string which has lots of html like images, bold and italics.
I used code as follows:
content.setText(Html.fromHtml(articledet.toString(), imgGetter, null));
I just want the links should be click-able. I achieved that easily. What I want when user clicks on the link, link should be opened in browser but I also want to track what external links where clicked.
i.e. On click of link, I should be able to write URL in a file.
I can do that using spanned. But if I used spanned then, I have load images, that will stop working.
Please help me with this.
Related
I have html string. I need to show my it in my TextView. Here is my code:
tvText.setText(Html.fromHtml(htmlString));
Html string contains some text, but may also contains links. I need to detect if a string contains a link, make part of that string clickable.
I can do a search for links in a string myself and then use SpannableString and ClickableSpan.
But perhaps there is some way to set a click in html and then the mobile application will be able to react for some reason and make part of the string clickable.
Please help me.
UPD: I can request an html string in any form, so I need to understand what it should be in order to process a click in a mobile application without any search for links in string.
Try to wrap your links in html <a> tags and set movement method to your textView like this:
textView.setText(Html.fromHtml("This is a link"));
textView.setMovementMethod(LinkMovementMethod.getInstance());
So i have a html string which contains a
So after i set this in a text view in android
i need only the tag with the href tag inside of it to be clickable and then redirect it to the corresponding link . How can i do that.
"<body style='background-color:lightgreen;'><b style='color:red;'>App</b><br/>ABC <a href='redirect'>XYZ</a> App. Lorum Ipsum.</body>"
I want the XYZ link above to be set in a text view for which i am Using
Html.fromHtml()
after this the text is set . I want the "XYZ" text to be clickable and redirect me to the corresponding link. How can that be done?
Assuming you're using Java and not Kotlin, as you didn't point that out in your question, but this is the same idea.
If you want the textview to be clickable and have it work like a link
Use something like Pattern or Substring to manually parse the string to get the URL. (Bad idea)
Then set an setOnClickListener for the textView you want to redirect the user to. This should have an Intent and all that jazz in it.
I am creating a note application for myself. To style my notes, I write html tags, click a button and show styled version with html. from html.. But the problem is, I need to store the text with html tags not without it so when I get the data from the database, I get the text with style.
So I wonder is there any way to decode embedded html tags other than storing the string before html. from html function and acting accordingly? Also i can click the button anytime then continue typing which is very hard to track. Because i run this function to stylize ;
text.setText(Html.fromHtml(text.getText().toString()));
Which means i lose the tag info.
Thanks in advance.
If the user of the app write the html tags, the app should store them.
So as you suggest yourself, you will have to store the string before calling Html.fromHtml.
Help somebody, I am stuck.
The goal is to view html text with pictures and etc. and to be able catch longClick events on pieces of plain text. And then get this txt and do something with it.
If you are writing a custom application to load html documents then you should have the look at WebView documentation for it. It contains everything to guide you.
I am using a simple textview to show some html string in my android app. If I show only text with links I have no problem, but when I receive some data which contains images and tables the images are showing like obj string only and the tablet are not even shown, only the text part is showing. I know I can use webview, but i don't have so much control of the contents view and I can't customize it so much as in textview.
Is there any way that I can show tables and images in textview, while the images are saved on sd card. I don't need any methods to download them from internet and stuff like that.
Any help / suggestions / advices are appreciated!
No. TextView is not WebView. Use the latter for more markup that elementary attributes like <B>, <U> or tags like <A>