I want to develop a timeline view for Android, which is like a infinite scrolling Google Calendar day view.
Now I use a fixed length RelativeLayout in a ScrollView, and I think I should use AsyncTask to dynamically load the data.
-
I do not know if it is necessary to use
AsynTaskto load the data, because I just want to load some texts now. -
My idea is to set two points near the upper and lower borders of the
RelativeLayoutand load data when scroll across the points. Should I prepare the child views inAsyncTaskand attach them to theRelativeLayoutinonPostExecute()or create a newRelativeLayoutand then replace the old one inonPostExecute()?
What is the common practice? Thanks.
If you’re loading the data from a static array or some other data source that is already in memory, you may be able to get away with doing it on the UI thread. If you’re going to be loading the data from disk or network, you should (and in the case of network must) load it from a background thread (i.e. not the UI thread), and
AsyncTask<>is a great way to do that.Your approach seems reasonable. You may be able to memoize and reuse layouts as the user scrolls.