I have a viewpager that holds 3 different fragments and all fragments has tablelayout which loads dynamicaly. (while saying dynamically, I never try to reach any dataset, I take dataset from bundle already, what I do is just iterate dataset and during this process creating tablerows, textviews and inserting them into tablelayout by one by, so the issue is only creating view as dynamicaly)
My problem is while swiping between fragments it takes a while. I noticed it does that filling operation I mentioned above in oncreateview everytime.
What I want to do is it should create tablelayout just once at the begining and return it everytime as view if fragment would be selected.
When I try that fragments view appears only once and after swiping nothing appears.
I couldnt sleep and I am writing these via my cellphone, so I cant share what I did at the moment but I hope youll get what I want to do and maybe direct me in a good way.
You can use:
myViewPager.setOffscreenPageLimit(3);
which will keep a fragment around once it has been loaded.
Also, you really should use a ListView instead of building out TableRows. This will scroll much smoother and load faster.
Related
I want to loop my Viewpager and Im using the PagerAdapter extension. Everything I found in the net was an example with Fragments.
I want to solve this with a normal pageradapter. So When I Swipe from 1st view to left I want to be in the last View , and when I swipe from last view to right I want to change to 1st.
How can I solve this in an easy way (maybe without any libaries) ?
You can use the viewpager's setCurrentItem() method for achieving such functionality. This method takes the position (zero-based) of the view you want to navigate to.
https://github.com/TobiasBuchholz/CircularViewPager
I used this library, but there some problems in it when you try to show many circular views simultaneously
I am developing an activity with a ListView in which I need to change the current row by another layout by clicking on the row, and I'm not finding any way to do as much as I look (I take hours searching for possible solutions and I have not seen any reference to this problem). I do not know if this can be done in Android, but if anyone has an idea of how to do this would be appreciated.
Thanks in advance.
PS: The ListView control is normal and just want to replace a layout with a different layout. I'm using the API 15.
Use a ViewSwitcher
http://developer.android.com/reference/android/widget/ViewSwitcher.html
A ViewSwitcher is -
ViewAnimator that switches between two views, and has a factory from
which these views are created. You can either use the factory to
create the views, or add them yourself. A ViewSwitcher can only have
two child views, of which only one is shown at a time.
I suggest merging the two layouts in a single one and hide the second one. In your adapter data you should have a flag or something to indicate which layout to display. When you click a row, toggle that flag for the selected item and notifyDataSetChanged() on the adapter. This will make sure the changed layout remains even if you scroll up and down and the row goes off screen.
A more optimized solution is to have different item types in the adapter.
I have a ViewFlipper in which I display a large number of images, loaded from the sqlite database. If I initialise each ViewFlipper child on startup, there's an unreasonable delay whilst all the images are loaded from the db. Instead I want to populate the views one at a time, 'lazily', just before the user transitions from one child to the next. I need to populate the next view before setDisplayedChild(next) is called as I have animations applied to the transition. However ViewFlipper doesn't seem to have a getChildAt(int i) method which would enable me to do this - you only seem to be able to getDisplayedChild(). Any ideas how I might achieve this ?
Fixed it by keeping a list of views outside the view flipper - doh
I'm trying to show an animation with all Views that I've created from an adapter. When I scroll down, it shows the animation correctly, but when I scroll up, I see these Views recreate themselves and show the animation again. Then, when I scroll down, it happens again.
My assumption is that the mechanism of creating a View from an adapter is to load the View into memory; just the group of Views which are on screen right now (but above and below views are not loaded into memory). These will be loaded again when I scroll to these views, right?
Is there any way to fix this problem?
PS: Sorry for my English, I hope you understand my problem.
My assumption is that the mechanism of creating a View from an adapter
is to load the View into memory; just the group of Views which are on
screen right now (but above and below views are not loaded into
memory)
That's somewhat correct: a ListView will not try to visualize any data that isn't (at least partially) visible. It also 'recycles' views, meaning that any view that isn't currently used to present data to the user and is of the same 'type' as the next data item, may get reused.
Hence you shouldn't rely on persisting data with or make any assumptions about the existence of particular views. In stead, use something that's separate from the views; e.g. the dataset you're visualizing.
Quite often, you'll supply a list of POJOs to a BaseAdapter or ArrayAdapter. You could simply add a boolean to the POJO indicating whether it should animate or not, and change that whenever the animation for that particular item finishes. Alternatively, you could keep track of these values in a separate collection (which is probably the more straightforward approach if you're dealing with a Cursor as data source rather than POJOs).
I have an activity with a HorizontalScrollView. When it opens, I start filling this view (or rather, a container layout inside it) with another views. This is done from another thread by using handler.post.
The views are added in bunches of 15, and when there are no more views to add, I start updating them with new data (this is a kind of streaming data from a server).
The problem is that the scrollview is empty until all of the views are added. As soon as they are all added and start updating, the scrollview gets drawn.
How do I refresh it in the process of adding views? I don't want the screen to be empty for 3 seconds while all of the views are added.
Thanks a lot.
UPDATE: turned out this problem is not specific for HorizontalScrollView, this is the case for any generic layout.
Im not sure I understand exactly how your program is constructed, so that the views are not shown until you start updating... but perhaps myLayout.forceLayout() helps?
The thing is ofcourse that layout only gets shown after onCreate().
I could imagine you use a AsyncTask to perform data lookup and use the callbacks provided in that class to update the UI, since they run on the main thread. This way you can just finish the onCreate(), and then start updating your view.