Anshul
Anshul

Reputation: 9480

When custom Adapter required?

In most cases you will need to customize the Array Adapter to populate the layout used for each View to represent the underlying array data.

These are the lines from a book I am reading. But I am unable to understand why we require custom Adapter ?

Upvotes: 0

Views: 61

Answers (3)

G_S
G_S

Reputation: 7110

Consider the below situation : You are having a listview where each list item should have textview, an edit and delete button. See sample listitem below :

enter image description here

In such case it might be a bit difficult to design the list items without using custom adapters. The same can be achieved by designing a seperate layout for this listitem and attach this to the main list view using concept of custom adapters.

Hope you understood. If it is not yet clear, you can ask for further clarification.

Happy coding

Upvotes: 1

Emmanuel
Emmanuel

Reputation: 13223

For example if you want to give the rows of a ListView a custom layout. It is true that you can create a layout in which you have a TextView and the data will bind just fine, but how would you go about binding information to more than one TextView? You will need to bind this data manually using a custom Adapter.

Upvotes: 1

Egor
Egor

Reputation: 40203

An ArrayAdapter will bind the String representation of every object it holds to a TextView inside the row layout. Whenever you have more than one View in your row layout you'll need a custom Adapter or a customized version of ArrayAdapter. You can refer to the documentation of ArrayAdapter for a more detailed description of how it works.

Upvotes: 1

Related Questions