CardView Android Studio


CardView Android Studio example gives a further developed and adaptable method for executing unpredictable and custom listview with greater usefulness that is required these days for our applications.

In this post, you will learn about the implementation of the CardView Android Studio. This example of CardView contains one image and three textView.Outline. Android 7.0 presents another gadget called CardView which basically can be thought of as a FrameLayout with adjusted corners and shadow dependent on its height. Note that a CardView wraps a format and will frequently be the holder utilized in a design for everything inside a ListView or RecyclerView.


“It will good to cover my previous articles before this. It helps to learn more about Android development. In which I explained.”

CardView Android Studio example

The new supporting library in Android Lollipop introduces new UI elements such as Recycle view and CardView.

  • The CardView is the element of Android Material Design.
  • A CardView also a view group. The CardView adds into Activity using an XML file.
  • Each card will represent a row in the RecyclerView.
  • A CardView is a new widget that shows all the information on a card.
  • A CardView is like a container where you can place images and as well as textView.
  • CardView is a component that looks like a card.
  • cardUseCompatPadding
Set the padding between the edges of the CardView and children of CardView.
  • CardBackgroundColor
This property defines the Background color of the CardView android.
  • cardMaxElevation
If you want to choose Elevation dynamically then use cardMaxElevation.
  • cardConerRadius
Define the corner radius of the card.
  • cardPreventCornerOverlap
Use for Content padding enables and disable.

Create a CardView

The following step has completed

  • Add the library in the Dependence section.
  • Single Row layout created.
  • Created adapter.
  • Define a Datasource.

Resource section

Adding resources in the Grade file is your first task. You can use the CardView widget to run the older device The following elements added to the dependency section.

To make a CardView Android Studio example you would need to add the following code to your XML.

After that create a single_row layout. This layout contains the one textView and one image. The CardView contains one image and text view.

  • The Image shows the Movie icons.
  • A TexView display the phone number

It is prescribed to utilize a compartment see like RelativeLayout or LinearLayout as the main kid and CardView used as a child. then place all the content inside the layout.

The XML will look like.

The single row layout shows you the following output with one image and one text view.

Alt tag CardView Android Studio example

  • Create a new class
  • Name of the class ContactNumber 
  • Define some variables and set the getter and setter method. “<Paste the following code on an activity that hosts the layout>”

  • Create a new class
  • This class implements the RecycleAdapter.
  • The name of the class ContAdapter extends RecyclerView

The RecycleAdapter class contains three methods.

  • onCreateViewHolder()
  • OnBindViewHolder()
  • getItemCount()

getItemCount()– will return the value of count how many time you want to inflate your custom view.

OnBindViewHolder()– performing all the action from event handling. Means while performing all the actions of view.

onCreateViewHolder() a technique where you will pass your custom view format to inflate it with LayoutInflater and in this strategy just you have to make an Object of RecyclerviewHolder class additionally after that you will restore this view question in this strategy.

“<Paste the following code on an activity that hosts the layout>”

Alt tag CardView Android Studio example

 Data Source

In a ListView and RecycerView, the adapter is used to map the data. You should define Datasource before creating an adapter. The data source will be JSON a string resource Array list.


The Layout Manager manages the position of each item. The layout manager converted the XML appearance into java. simple define the layout Manager and extend it.


This Adapter pursues the view holder configuration design, which implies that to characterize a custom class that expands RecyclerView.ViewHolder. To make an Adapter in a Listview CardView as well as CardView can utilize, you should extend it RecyclerView.Adapter.

“<Paste the following code on an activity that hosts the layout> File: MainActivity

Here run the application and see the amazing output. the output contains one image and one textView. but you can custom it as you want.

Alt tag CardView Android Studio example
Wrap up

I had explained what is CardView. how created it. In this instructional exercise, you have figured out how to utilize the CardView and RecyclerView gadgets that were presented in Android Lollipop. You have likewise observed precedents of how to make utilization of these gadgets in Material Design applications.

Previous articleHow to Code RecyclerView Android Studio Easy Way
Next articleSimple Way to Create Android Splash Screen
My name is Muhammad Zubair. I want to help you a lot of things that a blog provide. You feel free to ask the question anytime you might have! While most recently, he tends to share her wealth of knowledge and expertise on SEO, link building, inbound marketing,