Un Adapter gestisce il modello dati e li adatta nelle righe individuali della collezioni di dati della finestra.
Ogni linea nella list view consiste di un layout che può essere complesso quanto si vuole.

Definizione

Adapter: un pattern, consente di associare il dato all'interno di una collezione (come ArrayList) ad un template grafico. Viene ripetuto tante volte quanti sono i dati tra il widget del template con il valore dell'attributo del nostro dato.

ListView Layout
...

<ListView>
	android:id="@+id/id_listview_sample"
	// ...
</ListView>
Nota

Tutti gli adapter elencati ereditano dal BaseAdapter, il quale ha tra i metodi getView, getItem, getCount, getItem, getItemId...

Cursor Adapter
...

Per visualizzare oggetti complessi ricevuti dal database si utilizzano i CursorAdapter, che vengono utilizzati nelle ListView e altri componenti.

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;
public class CustomCursorAdapter extends CursorAdapter {
  public CustomCursorAdapter(Context context, Cursor c) {
    super(context, c);
  }
  @Override
  public View newView(Context context, Cursor cursor, ViewGroup parent) {
    // when the view will be created for first time,
    // we need to tell the adapters, how each item will look
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View retView = inflater.inflate(R.layout.single_row_item, parent, false);
    return retView;
  }
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    // here we are setting our data
    // that means, take the data from the cursor and put it in views
    TextView textViewPersonName =
        (TextView) view.findViewById(R.id.tv_person_name);
    textViewPersonName.setText(
        cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1))));
    TextView textViewPersonSurname =
        (TextView) view.findViewById(R.id.tv_person_surname);
    textViewPersonSurname(
        cursor.getString(cursor.getColumnIndex(cursor.getColumnName(2))));
  }
}

Fragment
...

User navigates backward or fragment is removed/replaced

The fragment is added to the back stack, then removed/replaced

The fragment returns to the layout from the back stack

Fragment is added

onAttach

onCreate

onCreateView

onActivityCreated

onStart

onResume

Fragment is active

onPause

onStop

onDestroyView

onDestroy

onDetach

Fragment is destroyed