How to Use Adapter While Filling Layouts - android

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/

Related

How do I implement staggered views in reading order?

Here is what I want to implement:
I'm trying to display definitions I'm getting from the web (right now they're coming from dummy data, but that's neither here nor there).
My first thought was to use a horizontal StaggeredGridView. There are two problems with this. The views are not laid out in the correct order and the span count is not set dynamically. Also, I found out that calling setSpanCount() in onLayoutChildren() causes an error at run time.
Of course, I could just have a LinearLayout and forego my attempt to recycle views. That would work in most cases, but if the user did happen upon a length definition, it would be very memory inefficient.
With that in mind, I resolved to subclass StaggeredGridLayoutManager. And this is where I need your help. Here are the resources I found in my own search:
Google's Implementation of a LinearLayoutManager
A Guide Implementing a Custom LayoutManager
Another Guide for Implementing a Custom LayoutManager
An Overview of a Few Principles to Follow when Implementing a Custom LayoutManager
I went through each one of these, but I cannot mentally separate out what parts are there for their specific use-cases and what parts are common to all custom implementations. If someone could be so kind as to point me in the direction of a resource or explain what all the methods I have to call in what order and for what purpose, I would be immensely grateful. Thank you!
Your first screenshot looks like a perfect case for Google's FlexboxLayout library. You can use the FlexboxLayoutManager with RecyclerView to get exactly what you showed.

Is there an alternative to gridview with adapter?

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

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.

Grid with different item height and width

can someone help me and tell me is this possible in android. I need to have in my app a gridview alike widget, but with different item height and width, like this:
So is this possible, and if so, what can I use to achieve this.
Thanks
For this you need a work around or you can say a third party Library named as "AndroidStaggeredGrid"
You can check it on here
#Darko,
Yes, it it possible to do like this in Android.
There are many ways to implement this. As you said GridView cannot be used to achieve this. For a normal user this will appear has grids.
Ways:
Use fragment for each and every "grid" you can see and each fragment will have its layout to display either 2 or 3 images in grid (No gridview is required here too). Use ImageViews as usually.
If the layout design is same, then you can define a single layout with internal design in the same format. Each row with imageviews - This is not encouraged by the way.
Design layouts for each and every format of design per row. Inflate each particular row to a list (using custom adapter). Based on position in getView() you can control which row design to be added to list. Inbuilt scroll in ListView, so no problem!
I suggest you to go with number #1 or #3. Using fragments you will have better control.
If you come to know any better idea, please share!
It's StaggeredGridView
You can find an implementation at https://github.com/bulletnoid/StaggeredGridView
It's possible using GridLayout. More details in the link.
http://developer.android.com/reference/android/widget/GridLayout.html

ViewPager + recycling views?

I'd like to create a gallery of photos that swipe left and right. At first I took a look at Gallery, but it's marked as deprecated.
http://developer.android.com/reference/android/widget/Gallery.html
We're told to try ViewPager instead. But the PagerAdapter class doesn't handle recycling of views for us (like a standard ListView), does it?
http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html
Is it up to us to build the recycling mechanism?
Thanks
But the PagerAdapter class doesn't handle recycling of views for us
(like a standard ListView), does it?
No, and I think it's because it was built assuming you are using different layouts for each of the page.
Also, as it is not being scrolled as fast as a ListView (you cannot "fling" a ViewPager to skip multiple pages), I think it doesn't need to have to recycle.
This HorizontalListView is great, i used it to do exactly what you want.
see the link in the edit on this question The link in the Edit, and the answers give you some possible ways to solve.
There is also a HorizontalListView online somewhere if you search for it that makes a fine replacement for Gallery and does recycle its views.

Categories

Resources