Reputation:
I am using ListView in android
My data is coming from database
I Have learned SimpleCursorAdapter and this is the code from official docs
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.person_name_and_number, cursor, fromColumns, toViews, 0);
ListView listView = getListView();
listView.setAdapter(adapter);
All the thing i have understand successfully created the list view also but there is one doubt what the use of last argument 0 in the constructor they have not explained. Please tell me what this last argument is doing here.
Upvotes: 0
Views: 372
Reputation: 261
Listview from Cursor (without Loaders)
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
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"
);
Listview from Cursor (Using Loaders)
To Asynchronously load data to the Containers(Listview or Fragments) Loaders are best approach.
// 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);
The following URL describes above. http://www.androiddesignpatterns.com/2012/07/understanding-loadermanager.html
Upvotes: 0
Reputation: 10011
The SimpleCursorAdapter documentation explains that these are flags used to determine the behavior of the adapter:
Flags used to determine the behavior of the adapter, as per CursorAdapter(Context, Cursor, int).
See the CursorAdapter docs for more information.
Upvotes: 1