0

AndroidでListViewを使用しています

私のデータはデータベースから来ています

私はSimpleCursorAdapterを学びました。これは公式ドキュメントのコードです

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
        R.layout.person_name_and_number, cursor, fromColumns, toViews, 0);
ListView listView = getListView();
listView.setAdapter(adapter);

私が理解していることはすべて、リストビューも正常に作成されましたが、説明されていないコンストラクターで最後の引数 0 を使用することに疑問があります。この最後の議論がここで何をしているのか教えてください。

4

2 に答える 2

1

SimpleCursorAdapterのドキュメントでは、これらはアダプターの動作を決定するために使用されるフラグであると説明されています。

CursorAdapter(Context, Cursor, int) に従って、アダプターの動作を決定するために使用されるフラグ。

詳細については、CursorAdapter のドキュメントを参照してください。

于 2013-03-15T12:58:55.447 に答える
0

カーソルからのリストビュー(ローダーなし)

SimpleCursorAdapterアダプター=newSimpleCursorAdapter(

    this,                // The Activity context
    R.layout.list_item,  // Points to the XML for a list item
    cursor,              // Cursor that contains the data to display
    dataColumns,         // Bind the data in column "text_column"...
    viewIDs              // ...to the TextView with id "R.id.text_view"

    );

カーソルからのリストビュー(ローダーを使用)

コンテナ(リストビューまたはフラグメント)にデータを非同期的にロードするにはローダーが最善のアプローチです。

// Initialize the adapter. Note that we pass a "null" Cursor as the
// third argument. We will pass the adapter a Cursor only when the
// data has finished loading for the first time (i.e. when the
// LoaderManager delivers the data to onLoadFinished). Also note
// that we have passed the "0" flag as the last argument. This
// prevents the adapter from registering a ContentObserver for the
// Cursor (the CursorLoader will do this for us!).
mAdapter = new SimpleCursorAdapter(this, R.layout.list_item,
    null, dataColumns, viewIDs, 0);

上記のURLは次のとおりです。 http://www.androiddesignpatterns.com/2012/07/understanding-loadermanager.html

于 2013-03-15T13:10:58.347 に答える