Android, what happens to Listview if IME pops up? - android

I have a listview inside a fragment. When IME pops up the listview is resized, but I want to know what happens in code behind for that listview. As for what I have observed the listview's notifydatasetchanged() method is not called because it will refresh the listview but this is not the state here. The only thing I see is that the view of the list item is updated not the whole listview.
Could anyone clarify whats happening to the listview?
Thank you.

If you have adjustResize as your softInputMode, the entire window is resized, causing a relayout to happen. Any scrollable containers are adjusted so that the focused view is visible. If you have adjustPan, the window is only moved, but not resized.
None of this has anything to do with data. In fact, in both cases the view doesn't even need to requery the adapter since either its size is getting smaller (it will discard views), or its size will be exactly the same, just off screen.
What are you trying to achieve that you're asking this question?

Related

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.

How to force start animation if view out of window

I have a scroll view with several views and only one view can be expanded. When another view gets expanded the already expanded view gets shrunk. But the animation for the not visible item on the screen gets started only when the view gets visible.
So is there a way to force start the animation?
Setting the height for not visible item causes unwanted jumping of scroll Y if the view is on top and view on bottom gets expanded.
I had the exact same problem and was so happy, that i found the question on SO, only to find out that no one had answered it. I looked around for a solution but didnt really find one. So what i did in the end was to check if the item was in the visible area (was pretty easy for me, since i used a custom pager) and set the animation time on the invisible items to 0.
Worked for me, but i dont know if this will work/worked for you.
PS: I would have posted a comment instead of an answer but i think i am not allowed yet.
Since nobody knowing this, I must assume this cannot be done.
You just invalidate the invisible view by invalidate() method.

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