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.
Related
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.
I'm developing a mobile app in jQueryMobile and PhoneGap. Often, due to the nature of jQM or because it's about loading data, a page will need some last-minute adjustments before it is shown. For example, form fields need to be filled in with dynamically retrieved data, or the contents of list items need to be given a slightly different style in order to fit better.
I am currently doing all these adjustments using the pageBeforeShow event handler. But I wonder if I shouldn't have been using the pageBeforeChange event handler. The jQM docs do not really make it clear how these two events relate to each other, i.e. which is fired first.
What I know
I do know the following
pageBeforeShow and pageShow are triggered after all of jQM's markup (e.g. making list items look pretty) has been applied.
pageBeforeShow and pageShow are bound to a specific page, whereas pageChange is called whenever a change of page occurs (so if you want to make specifi changes to one page before the user gets there, you need to test the event.toPage property)
Why I'm asking
And this is the background why I want to know if page(Before)Change is a better candidate.
jQuery Mobile page transitions are awkward on many devices. The big issue on Android devices is that page changes are jumpy: regardless of the transition type (fade, pop, etc), the page being left by the user will pop back into view briefly after the new page has more or less finished in the browser.
In my experience, this occurs mostly when other animations are running or are started while the page transition takes place. Basically, the Android browser doesn't seem to want to apply transitions to elements that are not actually in view, and it will flip back and forth between jQM pages as a result.
I've already developed a workaround where I delay any markup and form adjustments for a page by about 1000ms, which prevents the flashing but does mean that the user may be seeing these adjustments happen on screen after the page has come into view.
This analysis makes me think that pageBeforeChange might be a better candidate for attaching any markup and form adjustments. But it will be a big rewrite of the code, and I don't know what unforeseen stuff I will be getting into. Anyone have any experience with these events?
I'm not sure pagebeforechange would be the best place to do this. I don't see pagebeforechange as a page-level event, but more of a site-level event. I use it mainly if I want to take over navigation or to build dynamic pages.
I use pageinit when I want to attach event handlers to a page. I use pagebeforeshow when I want to change the contents or look of a page before it is shown.
Hope this helps.
sorry for the confusing title. I will try to explain my problem.
My app displays some content day-wise in a ListView. The user is able to switch days back and forth (e.g. by swiping his finger to the left/right). Now I want to implement some nice transition effect (like the new Android market has).
The problem is, that the content is generated dynamically and it can take a while to load. Also you can move (theoretically) infinite days to to past or to the future.
How can I implement a nice looking transition that is responsive and also tells the user, that some work is done in the background.
Just to clarify, I'm not asking how a ListView or an AsyncTask works, but rather for design concepts for my idea.
Thanks in advance.
If I understand correctly what you mean, I think you should try and preload in background the previous and following page, and keep them in memory ready to come in with the swipe.
Every time you change day you would recycle one page of data to load a new one (in one direction or another).
Obviously the user can still swipe too fast and you won't have time to preload things, but in that case I don't think you can do anything better than transitioning in the page with a nice spinner in it (not a blocking dialog).
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.
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.