Parse complex HTML into Android TextView - android

I have an adapter that have to show HTML content obtained from a server, but I can't use a WebView for each adapter item because performance is terrible...
I think that the only possible solution is to parse each HTML into a TextView.
It looks like that in iOS, DTCoreText library achieves this. Is there any similar library in Android? Html.fromHtml() supports only some tags, and I need to show elements as lists, tables, embedded images and videos, emojis...

Half of what you cite (tables, embedded videos) is not supported by TextView, regardless of how you create the Spannable to show in it.
Hence, use WebView. Using a WebView as an "adapter item" is unlikely to work well; use one WebView for the entire content that you wish to display.
Or, use actual Android layouts for the various pieces, rather than trying to pretend that a TextView is a Web rendering component. Getting the videos to work may be tricky.

Related

How to show text with several images in android

I am working on an android app that will be used to learn few technologies from tutorials. Each tutorial will contain several images distributed across the text. Same as like the tutorials we read on websites.
What logic I should use to implement this. The text and images will be fetched from local database.
Check these links for ImageView and TextView in android.To have images in between you need to properly place imageviews between textviews. If you want to add images dynamically and if you are not sure about the number of images you are going to add, build your layout in Activity(or Fragment) class not using xml.
Make html pages out of them and use a WebView to display the html.

How do I display a list of heavily formatted text fragments in Android?

I am developing an Android App for a community forum and am struggling with how to display the conversations. One page consists of 30 posts, to which I am bound per API. The posts contain text with the usual formatting (strong, underline, etc.), but may also contain tables, blockquotes and some other blocklike elements. Most elements can be nested, e.g., the <table> block may be surrounded by <strong> tags. Each post consists of a header with a static layout and non-formatted text.
The approach I used so far is rendering the whole conversation as HTML in a WebView. This is very easy, since I can use CSS and Javascript to customize it and it is straightforward to implement. However, this method has some drawbacks:
WebViews are very heavy. Especially when animated gifs or large images are contained, scrolling and interaction becomes less smooth even on fast phones.
Interaction with the App is somewhat limited; It is much more difficult to scroll to a specific position when the View is rendered; mostly, because this must be handled via Javascript and one never knows about render times etc.
Buttons, Long touches, link clicks etc. must all be handled via Javascript, which, especially for the different touch events, is kind of cumbersome.
Now I was thinking of different ways to handle this. Options are the following:
Build a dynamical View hirarchy. All the inline tags could be Spans in TextViews, the rest would be some specific layouts. Disadvantages: I would have a large number of views on the screen, it is hard to generate the hierarchy properly and it is hard to, for example, have some block views be surrounded with <strong> tags.
A hybrid view, as the Gmail uses it. This also would need a lot of Javascript do calculate distances etc. and it is less flexible when the layout changes during display.
A ListView of 30 WebViews. WebViews are very heavy, so this may be unwise as well.
What is the best way to solve this? How are other, similar Apps solving this problem? Is there any way to make the Javascript stuff in WebViews more reliable and stable?
I think you hit the nail on the head with building the view hierarchy. I would probably create a custom list item layout for the rows, although a multiline text view would probably do the trick. Then to process the HTML you could use the Html Spanned builder. You would need to create a Html.TagHandler to deal with any html tags that the builder doesn't support though.

use one webview replace with the listview?

all, I am developing a app "forum client", I use the webview as each item in listview for showing the post list, there are pics, texts and some attachments which can be downloaded by user. it does work, but the webview is heavy component, need lots of system resources. so I have to find another method to show the post list. I found this question is the same with my problem, and the last post by author said, use "one webview with bunch of DIVs rendering the individual contents", but I cannot get it, so, what did he mean?
I think he meant that you should get all the HTML that you are showing in the different WebViews in each ListView item, wrap each in a div tag, then show that in one single WebView that the user can scroll. You should get much better performance since you will only have one WebView on-screen (and thus in memory) at one time, rather than one for each visible row which will take a lot of memory.

Android - Creating own buttons in webview, retrieving certain contents from website into webview

I'm currently doing a application (project) on android. I would like to know how to create my own buttons in webview, or creating a tab bar in webview. Also, I would want to retrieve certain contents from a website (or rather, from livejournal, to be specifc), like, I do not want the buttons that are in livejournal itself, I just want certain contents, maybe like some live journal posts. Is there any way I could do this?
Thank you so much in advance!
Instead of putting tabs in the WebView you should put the WebView in Tabs. As for pulling information from LiveJournal there are two possibilites. They either have a public api that you can access to get the data you want and use that to populate your app or they don't. If they don't your only recourse would be to pull in the raw html and try to parse it. At that point you might was well just use the webpage as is.

Android app display different blocks of text using the same views

I am sure there is a better way to do what I am doing in my apps. The current one I am trying to improve is a list of military cadences. The way I am doing it now is by loading html files in a web view.
What I would like to be able to do is have one view set up and just be able to add the text portion of what I would be displaying with the html file.
What would be the best method. I know this is probably a pretty simple thing to do with a sting or array but I am at the very beginner level and would need to be pointed in the right direction to do it.
Sounds like you are searching for ListView. You can make a List of what you like tho show to the user and stick that with the an Adapter to the ListView.

Categories

Resources