Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use a CursorLoader to show individual database records one by one
    primarykey
    data
    text
    <p>I'm trying to make a <code>ContentProvider</code> with each record containing a question and corresponding answer. And an Activity showing TextViews of each question and answer and a "Next" button below those TextViews. When the Next button is clicked I would like the next question and answer to show. </p> <p>I'm trying to use a CursorLoader and LoaderManager, because the CursorLoaders keep their data across <code>onStop()</code> and <code>onStart()</code>, and I am trying to learn about <code>CursorLoaders</code> and <code>LoaderManagers</code>.</p> <p>The examples I have found all use <code>setListAdapter()</code>, but I don't want my activity to look like a list. I've tried to go around this by using a <code>SimpleCursorAdapter</code> and using <code>bindView()</code> to my <code>main.xml</code> layout. Not sure that is going to work.</p> <p>If I had a plain Cursor I would use <code>moveToNext()</code>, but for a <code>LoaderManager</code> it seems I have to <code>restartLoader()</code> with a new query. I think creating a new query would cost more time than simply going to the next record with a cursor. Especially since I would have to know the position of the current or next record.</p> <p>So my question is: Can I use a <code>CursorLoader</code> and <code>LoaderManager</code> to go through a database, record by record without having to make a new query for the next record? Or are <code>CursorLoaders</code> and <code>LoaderManagers</code> really only for ListViews?</p> <p>Here is my code so far, I realize it's not much, but I have read and re-read Android's pages on Loaders and LoadManagers.</p> <pre><code> public class Main extends Activity implements LoaderManager.LoaderCallbacks&lt;Cursor&gt;{ SimpleCursorAdapter adapter; String curFilter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.main, null, new String[]{}, new int[]{R.id.questionText,R.id.answerText}, 0); LinearLayout mainLayout = (LinearLayout)findViewById(R.id.mainLayout); this.adapter.bindView(mainLayout, getApplicationContext(), null); this.getLoaderManager().initLoader(0,null, this); Button nextQuestionButton = (Button)this.findViewById(R.id.Nextbutton); nextQuestionButton.setOnClickListener(new OnClickListener() { @Override public void onClick (View v) { } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload