What does setScrollingCacheEnabled(); do? - android

I initially used this method: myListView.setScrollingCacheEnabled(false); to enhance my list view's scrolling performance. However, I feel like it is causing a small bug in my list view. And I am not sure what it actually does.
1 out of every 20 times I navigate to the activity or fragment that contains the list view. The list view is not visible, then when I touch the screen, it immediately appears.
What is the difference between myListView.setScrollingCacheEnabled(false); and myListView.setScrollingCacheEnabled(true); ?

Related

RecyclerView LayoutManager - force to keep a view even if not visible

I am animating views between two RecyclerView. The first one is something like a list of folders showing the first item as cover, clicking it opens a new view showing the folders content animating the cover to the first item. Clicking back animates all visible views back to the folder where they came from (the cover being the top most view). This looks great as long as the opened folder shows the first item. If I scroll down the first item will be offscreen and the back animation does not look that good anymore because the cover view is not animated (I'm only animating all visible views currently).
What I think would work is following: the LayoutManager could position the first item at a position shortly offscreen and keeps it as a special view in it's pool so that u always can access the first view and when I animate back to the folder view I can animate the cover in addition to all other currently visible items ( the cover will be animated from top of the screen).
This means I need following:
the LayoutManager must handle the first item as a special one that is not recycled (I may need it any time for the back animation)
the first item must always be layed out (either at the default position in the list, if it is visible or offscreen directly above the screen), again because I may need it at any time for the back animation
Can someone help me where to start here? I think this is possible with extending the LayoutManager but I don't know where to start...
Have you tried the following?
recView.getRecycledViewPool().setMaxRecycledViews(TYPE_XXXX, 0);

Center aligned selection with animation in ListView (?)

I need a component that works like the picture below but I'm having trouble coming up with some kind of decent solution that works.
I want the list to have a center locked selection but being scrollable with the d-pad. This is for an application running on a TV so no need for touch scroll. So when pressing down on the remote d-pad the list will scroll and a new item will size up and the current selected one will size down and the new selection will still be in the middle.
I've tried doing this using a ListView that I extended and programmatically scrolling when pressing down or up. On scroll finished I called notifyDatasetChanged() on the ListView for re-inflating of the childs and in the ListViews adapters getView() I made the animation of the view located at the current selected position.
This is not optimal since I need to call notifyDatasetChanged(), which re-inflates all visible views, for the animation to apply. The UI becomes laggy when doing this and scrolling fast. It's also not possible to make som kind of compress animation when current selected item goes out of selection. There is also some trouble with the end items (read views) such the first or last in the list when doing animation of them, the may sometimes go out of screen.
I think that his must have been done before and maybe I'm missing it when searching for an answer.
Have anyone done something similar or do you have some suggestions of how this can be achieved? Maybe I'm just starting of with the wrong component here..
Regards,
Kristoffer

How do I hide or show adapters/views using cwac-merge?

I have a fragment holding several lists, as you may guess the scrolling is a mess, so I give it a try to the cwac-merge adapter, it seems to do it's job fine, but I wanted to customize some of the items, i.e. I need some of the adapters to show or hide depending on how many items they have, right now empty list adapters are showing a blank space, and I would like to make them gone until items are retrieved.
On the screenshot (please excuse its blurred but Im not allowed to show the product yet) you can see I highlighted with red rectangles the empty spaces, where I'm setting the view to have Visibility = GONE.
Also one of these empty spaces is caused because an adapter has no items.
Is there a way to hide or show certain adapters or views inside the MergeAdapter so they don't occupy space?
Thanks
where I'm setting the view to have Visibility = GONE
IIRC, having a GONE row in a ListView is problematic in general. MergeAdapter should not have an impact on it.
Also one of these empty spaces is caused because an adapter has no items.
I rather doubt that. Hierarchy View should show you what is really going on.
Is there a way to hide or show certain adapters or views inside the MergeAdapter so they don't occupy space?
An adapter returning 0 from getCount() should occupy no space, if you call notifyDataSetChanged() on the MergeAdapter so that it can tell the ListView to redraw itself.

control when listView removes nonvisible views?

I find listView recycles its views too fast.
When my listView scrolls, views falls off the screen gets removed right away.
Each cell(row) has image loaded using universal-image-loader.
Views which fell off the screen has to reload the image when they comes back into visible area. (it shows the stub image for short time period and loads the correct image).
I definately need to keep the view recycling behavior, but can I modify the list view's behavior so that user won't notice constant reloading of images?(maybe I keep 2-3 times of # of views in a cache than a regular list view would)
Unfortunately the code for ListView and friends is horribly complicated by the fact that it's designed to scroll unevenly-sized items without knowing the height ahead of time. That makes it brutally difficult to run with anything but the default behavior. In addition, most of the methods you'd need access to, to easily customize the behavior are hidden or private. It would be a massive job to try and roll your own (across multiple platforms, subtleties of scrolling, flinging, dragging, scrolling, keyboard focus &c).
The best solution is probably to maintain an image cache that fills in lazily around the view positions that are active. Not neccesarily easy. But way easier that trying to mess with ListView.
A very useful API for this is ListView.setRecyclerListener(AbsListView.RecyclerListener listener), which gives you a hook to track which images are actively displayed.
I can suggest you to use a ScrollView instead of the list view. The ListView is designed to display a lot of data efficiently, that's why your off screen items are destroyed. In which concerns the scroll view, once loaded, you will be able to scroll up and down without recreating the off screen objects (because they ill not be destroyed).
See: http://developer.android.com/reference/android/widget/ScrollView.html
EDIT:
If it is mandatory for you to use the listView, you cluld take a look here: How do i prevent recycled ListView items from showing old content?
There is a posibility to override the listView getView method and keep more items not to be destroyed that the number the listView is keeping.

Button in ListView malfunctioning

I have a button in each item of a ListView whose background is defined by an XML, one background when enabled and another when disabled. When the ListView loads, it comes out correct. But, for some reason I can't figure out, if I scroll down and then scroll back up, the wrong background shows up.
I'd like to know the solution to this problem, but besides that, in general what I want to accomplish is this:
I have a button in the ListView to take the user to the website for the given item. If there is no website, I want the button to disappear, or be disabled. I seem to have the same problem with both options.
Thanks in advance for your efforts
It seems most likely that the problem lies with your getView() method. Android recycles views to save memory, so, for example, when you scroll down, it calls getView(int, View, ViewGroup) on your adapter where View is the item that just left the top of the screen. If you're not re-populating the item with the new data from the adapter, (ie, just returning convertView) it will put the View that left the top of the screen where the "new" one should be.

Categories

Resources