I searched for hours but didn't find a suitable solution for me.
What I want to do: in my ListFragment I use the onListItemClick(...) method to handle the click events. Here, I change the background of the row item. But unfortunately every time the onListItemClick(...) is called, also the getView() from the adapter is called and updates all 8 visible row items. That takes to much time: 0.5 seconds. Because the row layout is pretty complex (2 Images, 8 TextViews).
So I want to update only the row which is clicked. I want to use this solution but that has no effect, when the other 7 row items are updated anyways.
I already followed these advices to speed the list up, but it's still to slow.
Any help, ideas and thoughts are appreciated. :)
Thank you!
[EDIT]
Thanks to CommensWare for giving me some new ideas. What I did now was to check what traceview says. And the result is, that the delay is devided in two parts. The first 300ms of the delay takes the "FastXMLSerialzier.escapeAndAppendString()" with over 22.000 calls. That seems a lot! In the second half, many, maybe all, onMeasure()-methods of the views and layouts are called.
What I tried:
I filled every textview with static dummy values in the adapter and excluded the part with loading the images. It changes nothing, traceview shows the same picture.
In the second try, I looked at the LinearLayout of my list item and replaced every "wrap_content" I found with "match_parent" - nothing. Still the same.
I am still open for your thoughts and hints. :)
You have no control over when and how frequently getView() is called.
If it really takes 500ms for you to generate 8 row Views, then there is something wrong with your code. You can use Traceview to determine specifically where you are taking the time, so you can attempt to do something to improve performance (e.g., caching).
Related
I have a RecyclerView populated with a fixed amount of items. There are 4 rows that are designated as section headers and use a different layout. I'm trying to implement a "jump-to" for each section, but smoothScrollToPosition doesn't go to the right row, or even line up consistently on the wrong row.
Has anyone had any problems similar to this? I can post some of my code, but it's all rather basic. So before I do that, I thought I'd just ask in words.
So I did some research and testing of using a listview in a scrollview, and as a lot of people may know this is supposedly bad to do, since they both scroll. It also means I can't show the complete listview as it will wrap to be smaller.
I have seen places which re change the height of the listview to fix this problem but again most people say that it isn't preferred.
What I would like to know though is what is the preferred way of making a nonscrollable listview like view? Basically I want the exact same as the listview but obviously non scrolled and the height based on its contents. I would prefer to work with the layout in as much XML as possible, and I would like to be able to send my array list to it to view on screen. Unfortunately either my search skills are quite dull, as I haven't been able to find anywhere that really explains the preferred method so I thought I would ask here.
Thanks for your help.
<>Clarification Information
I thought I would put this here in case it will help, first off I basically want to show an image, with a list of comments (each one has an author and a text) below it, the comments themselves are obtained from an array and can change. I want the whole page to be scrollable though so I can either view more comments or go back up to the image.
Using a RecyclerView and an adapter supporting multiple item types you could make a list which shows an image on top and several comments below it. Generally you'd have to check what item corresponds to each position - in your case on position 0 you have an image and in every other position you'd have a comment. Then in your adapter's onCreateViewHolder and onBindViewHolder you would check the item type and handle them differently.
You could take a look at this answer for a short example.
Let me know if you'd need any other details and/ or sample codes to get the idea. :)
I have a ListView that I am calling smoothScrollBy() on. 95% of the time, the smoothScrollTo() behaves as intended. However there are times that it does not end up in the intended spot! I have verified that I am giving it the same value. I notice that the smooth scrolling is not so smooth when the errors are made, however there are no other tasks that my application is performing that I would have control over.
I am not quite sure what is going on in the background but a likely culprit is garbage collection.
95% accuracy is not good enough in this situation. I am going to have to implement some sort of a correction mechanism to make sure the ListView lands on the correct spot in these instances.
Is there a better way to use smoothScrollBy() other than simply calling view.smoothScrollBy(distance, time);?
sometimes it will be because of the timing issue. When the views are added to your listview and the time you do
view.smoothScrollBy(distance, time);
the listview or the ui still need not get refreshed. So do this in the views post thread with a specific delay. Eg.
view.postDelayed(new Runnable{
view.smoothScrollBy(distance, time);
},1000);
Try some of these:
Listview has its own scrolling mechanism. It scrolls when the content is added.
Assign listview height (android:layout_height) to match_parent or fill_parent.
If your assigning a adapter in a working thread. Do not perform any UI actions in the thread.
If these do not solve the issue. Please post the code where you assign the adapter to the list view if any. Or the relevant code.
Also the xml layout code.
Hope this helps.
Ok, I hope I don't get slammed for asking such an ambiguous question but I am stumped and don't even know how to ask this. I am going to try as best as possible to communicate my problem and will clarify if needed.
I have two cursors merged using MergeCursor. I also have a custom cursor adapter. In my custom cursor adapter I have overridden BindView. I am noticing strange behavior where items are not showing up in my listview. Essentially I have two textviews for each row in the listview. In the last row one of the fields is empty.
I step through the BindView and I notice it gets executed 3 times. My listview only has 7 items in it (so that's 7x3). All of them show on the screen except one of the fields in item 7. I notice that on two passes though BindView a field value is missing.
What I want to know is, why is BindView executing 3 times. So when I say 3 I mean 3x7. 7 items in the list, so it cycles through BindView 21 times. I hope I'm making sense.
Please don't slam me if this is not clear. I am happy to modify or provide additional info.
What I want to know is, why is BindView executing 3 times. So when I say 3 I mean 3x7. 7 items in the list, so it cycles through BindView 21 times. I hope I'm making sense.
When ListView goes trough the measure phase, it will call newView and bindView on your adapter so it can set the dimensions of the rows (its children) and determine it's own dimensions. In the process, it doesn't retain the views, so they need to be recreated when the views are drawn on the screen. You can look at the ListView source so see exactly what it's doing.
My app polls a server every 15 seconds to see if there are any new items to display, then downloads the new items and disposes of the old items so that there are always exactly 100 items in the GridView. Unfortunately, this process can be confusing to the user if they see a page of images change without knowing where the items went.
My idea is that there could be some kind of animation (such as the new items being inserted at the top and pushing the older ones down the list) to show what action is happening. Unfortunately, I have no clue how to make this animation happen.
Is my idea even possible? How would I accomplish this?
Ben,
I know it's been almost a year since you posted this question. But I thought this might help you out.
http://developer.android.com/reference/android/view/animation/GridLayoutAnimationController.html
I think you will have to extend this layout and somehow pass in the position of the changes.
There are like 10 animations examples in the sdk (you will have to download them using the updates manager); the example is called "API demos". First, you can take a look of the Views -> animations examples... though, in your case the more interesting ones can be found in Views -> LayoutAnimatons.