Is there an alternative to gridview with adapter? - android

I created a gridview with a custom ArrayAdapter. Inside of the gridView is a couple of TextViews, an EditText and a Spinner. Everything was going fine until I added listeners to the Spinner and the EditText. Aside from the trouble of getting these to work (a lot of issues with the recycling) now it is lagging quite heavily. I read around and it seems that this is an inherent issue.
There is up to 16 items. Doing this manually in a Gridlayout or something would cause a ton of manual repeated work, which is why I went with a GridView and adapter. But the performance issues is a major problem.
So is there a way I can duplicate the functionality of a GridView without the issues that I am running into?
If someone thinks they can solve my performance issues with the current code I am happy to post. It is pretty standard ArrayAdapter using the viewholder pattern. Thanks
UPDATE:
Ok, so I ended up just going with the RecyclerView using the pattern laid out in this accepted answer Saving EditText content in RecyclerView After some tweaking to my code I have gotten rid of the lag.

Why dont you use a RecyclerView? It is meant for situations where you need to do a large number of calls to repeated patterns like in your gridview. It is much more efficient than gridview/listview for complex layouts.

You can try using TableLayout and see if it improves things. You can add all your rows as rows of TableLayout.
TableLayout

Related

Is it inefficient to use RecyclerView's Nested Adapters?

Hi, I'm working on a little complicated dynamic recyclerview right now.
To explain, there is an item in MainRecyclerView like the picture.
This Mainitem is dynamically added/deleted whenever the button is clicked.
And as you can see from the picture, the Mainitem has a SubRecyclerView inside it again.
SubRecyclerview is also added/removed dynamically through the button in the photo.
At least as a beginner, I think that to implement this, there must be an Adapter for MainRecyclerView and an Adapter for SubRecyclerView inside it.
But I think I've seen somewhere that these nested Adapters are difficult to implement and inefficient.
What do you think?
Is there any better way? Or a library for this.
Nested RecyclerView's are fine if implemented in right way.
Performance improvement of RecyclerView's in general could be done using:
RecyclerView caching,
GPU rendering optimisation,
RecyclerView.RecycledViewPool,
RecyclerView prefetch
And, Most important thing is that RecyclerView doing his job -> recycling views.
Additional content that might help you to improve RecyclerView performance:
Gpu Rendering -> https://developer.android.com/topic/performance/rendering/inspect-gpu-rendering
Slow rendering -> https://developer.android.com/topic/performance
If you don't know what is causing performance issue, then try isolated metod by testing part by part manually. Eg. If you have 10 ViewHolders, start measuring performance with first one by disabling all other ViewHolders, then try to increase ViewHolders types in adapters and measure again.

New gridview component with external scroll introduces empty frames when scrolling too fast

Hello
Thanks for checking my topic out! I will not go into depth why I have created this component, but safe to say for my specific application it was needed :)
The component is quite large so i used pastebin for this occation: http://pastebin.com/6jcmySr3
The problem
The issue here is not what you perhaps expected. The component works just great as a external GridView component to be used in a external ScrollView compared to the original one that android offers. Scroll normally and it will update the adapter Items correctly to the location you expected them to have. The issue I am having, is that if you scroll too fast the new location of the item might end up to be wrong and I can not figure out why.
My guess thus far have been that the newItemLocation-variable updates too fast when you scroll and the location where the view should have been moved is wrong, or that the view-update logic through getView updates too slow. In which case, I don't really have a solution for any of them. Could someone point me into the right direction?
Thanks!
*Edit: I am also using a ViewHolder pattern in my Adapter, so it's not because of that :)
I got the similar issue like you, the grid view will become empty or other strange cases(like display only one side without the other side when using etsy-like StaggeredGrideView), so I find a possible solution that can highly reduce the chance occurring this problem, you can try to set the min height of your TextView like android:minLines="n" or android:singleLine="true" in your GridView items(if you). That means the problem may be occurred when rendering the height of the TextView. Just try it~ =)
You can refer this post as well ==> Android: Gridview going blank while scrolling fast

Android engineering: ListView versus just a dynamic LinearLayout

When you are working with a long, big list, certainly one should use ListView because it handles cell recycling.
Notice here, for example Can i use nested linearlayouts instead of list view, for a big list? the OP is asking about ListView verses a dynamic LinearList -- the answer is "have to use a ListView, because of recycling"
Now, say you are making a short list -- imagine say a popup with only 10 or 20 items. It may even fit all on the one screen, so there's no recycling.
In fact, is there any difference between using a ListView and just using a LinearLayout, and dynamically populating the little views inside it?
It seems to me that the latter is in many cases much simpler, more elegant, and easier to work with. But I could well be missing something that seasoned Android engineers know about.
Should I just use an ordinary LinearList (populate it dynamically) for lists where recycling is not relevant? What's the usual, and why? Cheers!
{Incidentally, for popup cases, is there some better, lightweight method for "choose one from a popup-list" that I'm too silly to know about?! :) )
ListView(and other lists) supports very useful idea: splitting data and view. These parts could be changed at any time so it's important to support flexibility. And it could be solved by special mediator object: Adapter. Adapter roughly speaking says how to fill your view with particular data item.
So I'm sure that if you decide to use LinearLayout sooner or later you will implement you own Adapter.
If you used dynamic linear view then rendering the view will take more time as compare to listview. In listview we are rendering views which are visible only but if you used dynamic linear view then its problem.

How to Use Adapter While Filling Layouts

I know it may be weird that I want to succeed.
Let me explain whole in details. Firstly, I want to use two ListView looking in an Activity screen. Just like how Pinterest looks like. (I'm not sure is it true but it's named as heterogeneous gridview.) There is also one thing that I needed to implement: lazy loading. There are about 30 images in my activity, so that's not good to fetch all images at one time. That's why I needed lazy load.
So in first, I pondered on that I how obtain that appearance, I mean heterogeneous gridview. Then decided to add to LinearLayout in a ScrollView. Linears have vertical orientation. With thay approach, I added my new views by using odd-even method in Linear Layouts.
Althought, there weren't any adapter so according to my knowledge, there is no way to controll which items would be displayed. So lazy load is not suitable.
I've also tried two ListView in an Activity, but got some lag and also synchronous scroll problems. On the other hand it has a bad recycling.
So in this scenario, I want to ask is there way to fill LinearLayouts using Adapter? Or what would you recommend to create a heterogeneous gridview but also with lazy load.
If my approaches are wrong, I would not hasitate to change it.
Any clue would be great for me. If there is something unclear, please specify it. I'll explain with more details.
After a lot of research, finally I found a library which have lazy loading and heterogeneous gridview and also not has any scroll or recycling lags/problems.
Maurycy's StaggeredGridView is completely what I'm looking for.
Here is the library and also there is a demo too.
If I get your question right, here is what you need: http://spinlist.autsia.com/

Android ListView scroll is slow

I got a list view that shows a standard image text items, I use the standard ArrayAdapter to work with the view.
My problem is that the scrolling get stuck and not very smooth.
I done some profiling, and found that most of the time a Measure operation is in progress(for many controls most of them are containers)
Is it possible to make stuff work faster? where to start?
Here is very nice presentation about ListView performance http://www.google.com/events/io/2010/sessions/world-of-listview-android.html
Edit: This article may also help http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/

Categories

Resources