CursorAdapterとは

ListViewにArrayAdapterを適用するのではなく、CursorAdapterを使用した方がカーソルが当たっている箇所のビューのみに順次データを埋め込めて、無駄が少ない感じなのでは。
曖昧なので、公式サイトは何と言っているのか確かめてみる。

CursorAdapter | Android Developers

Class Overview

Adapter that exposes data from a 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.

※_idはXXXContractクラス内のXXXEntryクラス(public static final)でimplements BaseColumnsとすれば、自動的に生成されます。

Public Constructors

CursorAdapter(Context context, Cursor c, int flags)
Recommended constructor.

CursorAdapterの小クラスでオーバライドするメソッド

  • bindView(View view, Context context, Cursor cursor)
Bind an existing view to the data pointed to by cursor

※このメソッド内でビューにデータをバインドします
※setTextやsetImageResourceする
※子ビューはCursorAdapterの小クラス内のpublic static classでキャッシュします

  • newView(Context context, Cursor cursor, ViewGroup parent)
Makes a new view to hold the data pointed to by cursor.

※LayoutInflateしたviewを返す
※setTagもしておく

  • LayoutInflater
Instantiates a layout XML file into its corresponding View objects.

LayoutInflater | Android Developers

http://developer.android.com/reference/android/view/LayoutInflater.html#from(android.content.Context)

  • setTag (Object tag)
Sets the tag associated with this view.
A tag can be used to mark a view in its hierarchy
and does not have to be unique within the hierarchy.

Tags can also be used to store data within a view without resorting to another data structure.

http://developer.android.com/reference/android/view/View.html#setTag(java.lang.Object)

Fragmentの子クラスですること

implements LoaderManager.LoaderCallbacks<Cursor>
  • LoaderManagerとは
    Interface associated with an Activity or Fragment for managing one or more Loader instances associated with it.

This helps an application manage longer-running operations in conjunction with the Activity or Fragment lifecycle; the most common use of this is with a CursorLoader, however applications are free to write their own loaders for loading other types of data.

While the LoaderManager API was introduced in HONEYCOMB, a version of the API at is also available for use on older platforms through FragmentActivity.

See the blog post Fragments For All for more details.

※アクティビティとフラグメント間の長い連携用とのこと

LoaderManager | Android Developers

  • LoaderManager.LoaderCallbacksとは
Callback interface for a client to interact with the manager. 

※LoaderManagerとフラグメントが連携できるようにするとのことです

概要

Activity,FragmentがLoaderManagerを通して、連携している模様
FragmentはCursorAdapterと連携している模様

ContentProviderとContentResolverについても理解しないと難しそうな模様