Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:02:53+00:00 2026-06-09T00:02:53+00:00

I’m trying to make a ContentProvider with each record containing a question and corresponding

  • 0

I’m trying to make a ContentProvider 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.

I’m trying to use a CursorLoader and LoaderManager, because the CursorLoaders keep their data across onStop() and onStart(), and I am trying to learn about CursorLoaders and LoaderManagers.

The examples I have found all use setListAdapter(), but I don’t want my activity to look like a list. I’ve tried to go around this by using a SimpleCursorAdapter and using bindView() to my main.xml layout. Not sure that is going to work.

If I had a plain Cursor I would use moveToNext(), but for a LoaderManager it seems I have to restartLoader() 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.

So my question is: Can I use a CursorLoader and LoaderManager to go through a database, record by record without having to make a new query for the next record? Or are CursorLoaders and LoaderManagers really only for ListViews?

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.

 public class Main extends Activity implements LoaderManager.LoaderCallbacks<Cursor>{

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) {
        }               
    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:02:57+00:00Added an answer on June 9, 2026 at 12:02 am

    I understand that my question was vague, I was really lost. Here’s my answer, many months later, hope it helps someone who is in my past position.

    onCreateLoader() is automatically called when I call getLoaderManager().initLoader() or when there has been a change to the content provider (content provider has to call getContentResolver().notifyChange() for this to work). I provide the code to make the cursor loader when overwriting the method LoaderManager.LoaderCallbacks.onCreateLoader(). The cursor loader is automatically handed to onLoadFinished(). That’s it, I don’t touch the cursor loader again. onLoadFinished(), which is called automatically, receives a cursor (made from the cursor loader) as an argument. I update the adapter in my override of onLoadFinished() using the cursor argument, this.adapter.setCursor(cursor).

    SimpleCursorAdapter doesn’t have a moveToNext or moveToPrevious, so I made a SteppedAdapter, see below:

    public class SteppedAdapter {
        private Cursor cursor = null;
        // This class uses a reference which may be changed
        // by the calling class.
        public SteppedAdapter (Cursor cursor) {
        this.cursor = cursor;
        }
    
        private int getColumnIndexOrThrow (String columnName) {
        return cursor.getColumnIndexOrThrow(columnName);
        }   
    
        public void moveToNext () {     
        if (null != cursor && !cursor.isClosed()) {
            if (cursor.isLast()) {
                cursor.moveToFirst();
            }
            else {
                cursor.moveToNext();
            }
        }   
        }
    
        public void moveToPrevious () {
        if (null != cursor && !cursor.isClosed()) {
            if (cursor.isFirst()) {
                cursor.moveToLast();
            }
            else {
                cursor.moveToPrevious();
            }
        }
        }
    
        public String getCurrentTarget (String targetColumn) throws EmptyCursorException {
        int idx = cursor.getColumnIndex(targetColumn);  
        String value = null;
        try {
            value = cursor.getString(idx);  
        }
        catch (CursorIndexOutOfBoundsException e){
            if ( 0 == cursor.getCount()) {
                throw new EmptyCursorException("Cursor is empty: "+e.getMessage()); 
            }
            else {
                throw e;
            }
        }
        return value;
        }   
    
        public void setCursor (Cursor cursor) {
        this.cursor = cursor;
        }
    
        public void setCursorToNull () {
        this.cursor = null; 
        }
    
        public int getPosition () {
        return this.cursor.getPosition();
        }
    
        public boolean cursorIsClosed () {
        return this.cursor.isClosed();
        }   
    
        public int getCount () {
        return cursor.getCount();
        }
    } // end
    

    Since the adapter is set in onLoadFinished() using the method adapter.setCursor(Cursor), and cleared in onLoaderReset() using the method adapter.setCursorToNull(). Then the adapter has to have these methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.