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.
Related
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.
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.
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
Since RecyclerView uses ViewHolders, it means that you must have a predefined layout for each row. But what if each row needs to have a variable amount of views displayed?
For example, say I'm creating an instant messaging application where users can attach pictures to messages. They could attach anywhere from 0 to x pictures. When you create a RecyclerView to display these pictures (that are downloaded from a server), how would you make the rows include the correct number of ImageViews to display them?
There's a few ways I can think of doing this, but none really seem like good options.
Create ImageViews in onBindViewHolder, add them to a layout in the ViewHolder. (Isn't this what the ViewHolder tries to prevent? This would probably be laggy, especially with lots of pictures)
Restrict the amount of pictures the user can attach to a message to x, then add x ImageViews to the layout that are set to invisible/gone. In onBindViewHolder, set the ImageViews to display the picture and set these ImageViews visible. (What if I allow pictures & videos to be attached? Do I then need to add x ImageViews and x VideoViews as well?)
Put a GridView in each RecyclerView item and populate the GridView
inside onBindViewHolder. (I assume this would have no benefit over
option #1 because it's pretty much the same thing?)
That's all I can think of. Is there any other option that is designed for this sort of situation that I have not come across? Or what are the typical approaches taken towards this problem?
You need to create a heterogenous RecyclerView which will display multiple different ViewHolders. There are several ways to accomplish this.
The basic approach is that based on the number of photos/videos associated with each item in your RecyclerView.Adapter you would override getItemViewType(int position) (a method which is part of the RecyclerView.Adapter class) to return a different int. This int is the viewType parameter passed into createViewHolder(ViewGroup parent, int viewType). You would then use the correct ViewHolder/layout based on the viewType argument.
See here for a good tutorial.
If you don't mind using a library for an alternate approach I recommend AdapterDelegates.
I am learning android development and i am kinda stuck here. I want to create a friend list screen like shown in this picture.
What kind of activity should i use? Is there any available resources similar to what i want to achieve?
Thanks!
you can use ListActivity , also check out tutorials on lists, for example:
http://www.androidhive.info/2011/10/android-listview-tutorial/
http://www.vogella.com/tutorials/AndroidListView/article.html
you can find mire tutorials on google.
also you can use a regular Activity class with listView in the layout file
Use list view and custom adapter to populate the list view...
Listview should extend to the bottom but limit it just above the Type a name edit text and button.
Custom list view should contain linear layout horizontal in that include checkbox, Textview and Button
For type a name and Add use linear layout horizontal
Use listView with custom adapter , for array use arrayList<,friends,> sure you have to create friends class, in xml file put ListView then below that button and TextView