Recycler View or ListView? [duplicate] - java

This question already has answers here:
RecyclerView vs. ListView
(16 answers)
Closed 4 years ago.
I wanted to know when I should use RecyclerView over List View or ListView over RecyclerView and what difference does it make? I have used them both and I know for implementing we use a ViewHolder for RecyclerView. My question is specific to their inner implementation and performance of them over one another.
Edit: My question is that is there any place where ListView can be advantageous over RecyclerView? If not then why hasn't it been marked as depreciated by Google. Also, while we may find the ListView in the android:support library which is present by default if we create a new projec but for using RecyclerView we have to use another dependency.

The names are very descriptive in this case.
The ListView has been designed to display vertical lists of similar items. Its design however has one flaw, it is easy for developers to write not optimal ListViews which can result in slow, lagging scrolling of large amounts of items. The mentioned flaw has been addressed with the popular ViewHolder pattern.
The RecyclerView has been designed as a general purpose container of large amounts of items, which can be displayed as lists, grids or whatever you imagine and implement. The RecyclerView is considerably newer than the old ListView, this allows it to benefit with a few extras as default animations on items for free. The devil, in this case, is in the "general purpose" thing. The RecyclerView in most cases requires to write more code for simple things that would be required for the ListView. The extra complexity of the RecyclerView however, pays back in more advanced use cases.
More on the subject: RecyclerView vs. ListView

Related

how to show mutiple image in grid like facebook and linked in

I need to show multiple image in grid like example given here.
and also need plus icon while images is more than some certain counts
There are multiple ways to implement it
Two horizontal/vertical LinearLayout
TableLayout with two rows
ConstraintLayout which its children are chained together
GridView
RecyclerView with GridLayoutManager
and more ... :D
Possibly you want to fetch the images dynamically, and there are several collection views: RecyclerView, ListView etc. RecyclerView is common since you can modify the layout(for your case, columns) with various LayoutManagers. Since you haven't provide any code, I cannot help you with that, but here is a guide that might be helpful.
For the plus icon mechanism, you can modify your RecyclerViewAdapter code, limiting the count(in getItemCount()) to a certain number and visible a transculent foreground with '+number' in the ViewHolder code for the last item.

Expandable Items in ListView

I am writing my self a ListView that will contain multiple types of items. I have done that using ArrayAdapter and a ListView now my issue is that I need to have some Items inside my Adapter that is gonna expand and that will have inner items of any type. Now the issue is how can I do this? I know I can use ExpandableListView but I don't need some items to be expanded. I saw this post about something similar, The person suggested to use ExpandableListView or a Custom Item, I would like to do the Custom Item but my concern is that the OP of the answer quoted this.
If the number of items is low consider using a linearlayout to look
like a listview and another linearlayout for the last item.
I'm not sure what they mean by "low" How many items can I have inside it? Would it cause lag?
so my question is what is the best way to do this? I need to put items
in a ListView that is of multiple types, and one of the types can
expand and have inner views that can again contain the same types and
so on.
Edit: Since 2 of you confused of what I want. I want to do the following inside my ArrayAdapter
Item
Item
Item
ExpandableItem {
Item
Item
Item
Item
}
Item
Item
I am trying to make some of the Items expand to have more items inside them and control the onClick of the inner items and such.
About the meaning of "low": I think it's about performance but devices today are better than devices were in 2013 when the linked post was written - maybe you'll never experience a sluggish UI with your approach. Of course this depends not only on your UI structure but also on the type of data you'll be showing (videos or just text?) and on other factors like does the device have to perform heavy work in the background or not.
RecyclerView was developed to be a "better ListView", so if performance can be an issue, then maybe it is a good choice. (The adapters for both ViewGroups can handle different View types but RecyclerView offers a better means of showing changes to single items and customizing change animations, another point in its favor)
How can I do this?
Have different View types for expandable and flat items
You can "manually" expand/ shrink a View (AFAIK your only choice when working with ListView) by using some type of animation (or the Transition framework) but you always have to...
Keep track of the expanded state of each expandable item (e.g. in the Adapter) and use them in getView() respectively onBindViewHolder().
Add another ListView like RecyclerView on clicking of any item.

One large scrolling list of different items -> Better solution than RecyclerView?

I was prototyping an app with a recycler view where it boiled down to basically this concept:
There is one single list, which is entirely scrollable (this bit is important).
The items in question in the recycler view are however very heterogeneous. It is not like I want to have either an image or a text, but sometimes it is a simple "list item (clickable text)", sometimes it is a row with 3 buttons, sometimes it is an icon with text, another one is a button, etc.
While similar item types have similar behaviour, the groups itself are different. They need a different manager, a different ViewHolder to process their very different button events etc.
I find it not very convenient to put everything into the recycler view's adapter with some common base class and delegate everything those different items can do to some callbacks. It feels very clunky.
Is there some better way of handling that? The advantage of the recycler view is that it scrolls well. I personally do not need any lazy creation of those items (= recycling) so I am not winning much here. The other advantage is that I do not need to handle every items creation. Which is also the downside, I need to channel it through the adapter with its getItemViewType based on position etc.

How do I create a dynamically-generated CardView List?

I am wondering how we can create CardView Lists (dynamically generated cardview items). I'm surprised I can't find any info on how to create CardView lists on the developer.android.com site. I can usually find whatever I'm looking for.
I have seen quite a lot of stuff online but from what I've seen, its still using generic views, not CardViews. How can we create a list with cardviews?
I am wondering how we can create CardView Lists (dynamically generated cardview items)
Use ListView or RecyclerView. Use CardView as the root layout for your row layouts, wrapping around whatever the "real" stuff is in the row. And you're done.
RecyclerView will be the more common choice, simply because it was released at the same time as CardView. Many of my RecyclerView samples use CardView, such as this one and this one.
I'm surprised I can't find any info on how to create CardView lists on the developer.android.com site
That's because there is nothing much different about creating a list containing CardView widgets than there is about creating a list containing any other sort of widget. CardView is just a subclass of FrameLayout with a nice drop shadow effect. It is not rocket science, nor is it brain surgery.

Android: "Texting" List View?

I need some help.
I'm wanting to make an activity similar to this, but I'm not sure where to start.
Basically, it's like a texting UI, with the users question on the right and the answer on the left. I was going to use a list view for the sake of simplicity, but I dont' think it'd support this kind of structure.
I googled some layouts where I can scroll, but most of them require me to premake them, which isnt an option because its a dynamic chat log.
Does anyone here have experience with this kind of UI? Can you point me in any direction? I hate to ask such a strange question, but I don't even know how I'd word this situation on Google.
Thanks in advance.
What you're looking for is a ListView where you can return a different layout depending on whether the message is sent or received. A ListView is the most efficient implementation for this because its ideal for displaying a potentially large data set without having to keep a view in memory for every row.
This is achieved by extending the BaseAdapter in your application and overriding the getItemViewType(), getViewTypeCount(), and getView() methods (along with all the other methods required by a ListView adapter).
This is a good tutorial that serves as a walkthrough for this pattern.
Instead of using ListView, You may programmatically construct a viertical LinearLayout, and add TextView in each line, you can set the alignment of the TextView in lines accordingly.

Categories

Resources