http://developer.android.com/reference/android/app/LoaderManager.LoaderCallbacks.html#onLoadFinished(android.content.Loader, D) here you set the cursor to the adapter by calling swapCursor
How does a CursorAdapter load data from Cursor provided by CursorLoader in Android?
-
30-07-2022 - |
Вопрос
I have implemented the following code to display Contacts as a ListView
. MyAdapter
extends CursorAdapter
.
public class MainActivity extends FragmentActivity implements
LoaderManager.LoaderCallbacks<Cursor>{
private MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = (ListView)findViewById(R.id.listView_val);
adapter = new MyAdapter(this, null, 1);
lv.setAdapter(adapter);
.....
getSupportLoaderManager().initLoader(0, null, this);
}
.....
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { ..... } ....}
What I want to know is, how does the adapter
- mAdapter
know that it has to pick the data from the cursor
supplied by the CursorLoader
(Cursor
available after calling onCreateLoader
)?
Решение
Другие советы
This link provides with detailed example how the cursor adapter loads the data from cursor loader. Pass through next page also in the web link for the full answer. http://developer.android.com/training/load-data-background/setup-loader.html
Не связан с StackOverflow