Monday 9 March 2015

Adapter in Android


Why or where adapter is required?
-If you want to show a large data on screen says 200 or more records on screen then adapter will be more memory efficient.

Adapter
From Android Blog: An Adapter object acts as a bridge between an AdapterView and the underlying data for that view.


Adapter is a interface which is used to create the view from the data and give it to Adapter View. Adapter View will display the data on screen as per your need. Adapter is responsible for managing the data(index/position).


Adapter View: An AdapterView is a view whose children are determined by an Adapter. E.g: ListView, ExpandableListView, Gallery, GridView,, Spinner


What is the parent class of AdapterView abstract class?




Type of Adapters/ Adapters Architecture:




Difference between listadapter and Array Adapter:
When you use ListAdapter as the type for your variable, you are really interested in the interface. You may not be interested in calling some specific method of ArrayAdapter<String> not available in ListAdapter. That is mainly because you will just assign the adapter as the list adapter for the view.


ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songNames);


ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songsArray);


Difference Between ArrayAdapter and Simple Adapter
  • ArrayAdapter enables us to add in new item dynamically, even after the list is being shown during that time. Note that, ArrayAdapter is having method add.
  • SimpleAdapter is used for case where there are no more new item can be added.


Difference Between Cursor Adapter and Simple Cursor Adapter
  • CursorAdapter is abstract and is to be extended. On the other hand, SimpleCursorAdapter is not abstract.


  • SimpleCursorAdapter is a readymade widget from google and you just specify how your layout look like and what ids of widgets you want to fill with your chunks of data. You dont have to override methods of CursorAdapter and implement them. But you can use only TextView and ImageView in your layout, because it doesn't support more widgets so far.


  • CursorAdapter have more options for customization.




Interview Questions:
  • What is adapter?
  • What is Adapter View?
  • is Adapter an abstract class?
  • is BaseAdapter a class?
  • What is the immediate parent of Array Adapter?
  • What is the immediate parent of Simple Adapter?
  • What is the immediate parent of Cursor Adapter?
  • Can we create instance of CursorAdapter? Why?
  • Can we create instance of SimpleCursorAdapter? Why?
  • Which type of data does ArrayAdapter class accept?
  • Difference between listadapter and Array Adapter?
  • Difference Between ArrayAdapter and Simple Adapter?
  • Difference Between Cursor Adapter and Simple Cursor Adapter?
  • is AdapterView an interface?

No comments:

Post a Comment