-4

I know a list view needs an adapter, but WHY what is the purpose of it, and can it show lists without an adapter ?

Stavm
  • 7,833
  • 5
  • 44
  • 68

2 Answers2

1

From the docs:

An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.

The ListView needs to know which items to show, and needs to get Views for these items. The Android team chose to implement this using Adapters.


Note that for showing simple lists of Strings, there is the ArrayAdapter class.

nhaarman
  • 98,571
  • 55
  • 246
  • 278
1

An adapter manages the data model and adapts it to the individual rows in the list view.

Filtering and sorting of the data is handled by the adapter.

The notifyDataSetChanged() method on the adapter is called if the data has changed or if new data is available.

The notifyDataSetInvalidated() method is called if the data is not available anymore.

Also see What's the role of adapters in Android?

Community
  • 1
  • 1
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74