What Is Adapter In Android? The Beginner Guide

Adapter In Android
Share your knowledge.

If you are an android developer, or learning android development then you must have seen a adapter in android. By the end of this read you will be understanding about Adapter in android and you will be having a clear picture of what it is actually. It will be a complete beginner guide. Enjoy it

So basically an adapter will act as an bridge between the adapter data i.e content and the adapter view which shows or display the content on ui

In other words our adapter class will take care of the view creation and handling them for each of the adapter item.

2. Why We Should Use Adapter ?

When it comes to app development it is the responsibility of the app developer to make sure that the app is designed and developed to use less number of resources. You have to make sure that your app use less resources or efficient use of resources.

3. When To Use The Adapter ?

Suppose say you are making an Contacts app you will be showing a lot of user contact numbers in a list view. But your app will be used in different screen width devices.  So imagine your app built with below methods

Method 1 : Imagine you are not using a adapter. If you don’t use adapter and say you add a view to Root Layout dynamically then it will cause under efficient of resources and also require lots of memory. Because by doing this you are making 1000 of contacts to reside on main memory with there details.

Method 2 : Imagine you are using adapter. Now you don’t have to show the all data to user and all the contact details need not to reside in the main memory. Because since you are using adapter our adapter takes care of view creation. i.e It creates a specific number of views for your device and reuses those views on scrolling. This will lead us to efficient use of resources.

 

Not only contact app. Imagine you are making a gallery app where you will display images in grid view. you can use same concept there also.

4. What Are The Different Types Of Adapters Available In Android ?

Android has some built in adapters. And you can also create your custom adapter in your own way. Below are some different types of adapter available in android.

It is one of the basic adapter available in android. It is used to create a list view or a spinner. It is only suitable for views with one TextView only. For More Information visit ArrayAdapter

CursorAdapter  used to fetch data from Cursor to a ListView widget.

The Cursor must include a column named “_id” or this class will not work. Additionally, using MergeCursor with this class will not work if the merged Cursors have overlapping values in their “_id” columns.

It is An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views. For more information visit SimpleCursorAdapter

A spinner adapter allows to define two different views: one that shows the data in the spinner itself and one that shows the data in the drop down list when the spinner is pressed. For More Info visit SpinnerAdapter

5. When To Not Use Adapter ?

Just Because the android provides adapter you should not use it every time. Adapter should be used when dealing with a large set of data for efficient use of the resources. 

I am the guy responsible to make sure that everything that goes through this website has some value and gives some knowledge to the visitors. I have the habit of collecting quotes and I can't imagine my life without programming. I believe in self-education.
Posts created 4

Leave a Reply

Your email address will not be published. Required fields are marked *

Begin typing your search term above and press enter to search. Press ESC to cancel.