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 7545011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:49:13+00:00 2026-05-30T08:49:13+00:00

I am trying to convert my Android application to use the LoaderManager and CursorLoader.

  • 0

I am trying to convert my Android application to use the LoaderManager and CursorLoader. Basically, I have an SQLite database containing an ADDRESS column and a DISTANCE column, and I want to load the column values into my ListView rows.

Now, I have done a lot of research, and everything points to this tutorial: http://mobile.tutsplus.com/tutorials/android/android-sdk_content-providers/

It’s a nice tutorial, but there are a couple of things that I still don’t understand. Mainly, how do I construct the content URI that gets passed into ‘new CursorLoader()’? I’m not using any external data such from the device Contacts, etc.

Please see my code below. I am confused as to how to generate the value for BASE_URI:

public class FavoritesFragment extends ListFragment implements
    LoaderManager.LoaderCallbacks<Cursor> {

SimpleCursorAdapter mAdapter;

static final String[] FAVORITES_SUMMARY_PROJECTION = new String[] {
        MyApplication.COLUMN_ID, MyApplication.COLUMN_ADDRESS,
        MyApplication.COLUMN_DISTANCE, };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.locations_list_row, null, new String[] {
                    MyApplication.COLUMN_ADDRESS,
                    MyApplication.COLUMN_DISTANCE }, new int[] {
                    R.id.address2, R.id.distance }, 0);
    setListAdapter(mAdapter);

    getLoaderManager().initLoader(0, null, this);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // Insert desired behavior here.
}

public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(getActivity(), ***BASE_URI***,
            FAVORITES_SUMMARY_PROJECTION, null, null, null);
}

public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mAdapter.swapCursor(data);
}

public void onLoaderReset(Loader<Cursor> loader) {
    mAdapter.swapCursor(null);
}

}
  • 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-05-30T08:49:15+00:00Added an answer on May 30, 2026 at 8:49 am

    BASE_URI should be a static Uri defined in your ContentProvider, it is used so that when you make a query/update/insert/whatever to the ContentProvider, a UriMatcher which is also defined in the ContentProvider can output an Integer allowing you to use a Switch statement (as in the example of the query() method in that tutorial) to setup the right query to the correct table in your database. You should define a different BASE_URI for each table in your database.

    If you look at that tutorial they have defined a single Uri in the ContentProvider:

    private static final String TUTORIALS_BASE_PATH = "tutorials";
    public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
            + "/" + TUTORIALS_BASE_PATH);
    

    In your ContentProvider, you should change the value of TUTORIALS_BASE_PATH from "tutorials" to whatever the name of your table is that contains the ADDRESS and DISTANCE columns that you mentioned. Your CursorLoader constructor code would look like this:

    return new CursorLoader(getActivity(), YourContentProvider.CONTENT_URI,
                FAVORITES_SUMMARY_PROJECTION, null, null, null);
    

    For completeness, you should change the variable names to be more descriptive, so rather than TUTORIALS_BASE_PATH and CONTENT_URI, you should change it to something like LOCATIONS_BASE_PATH and LOCATIONS_URI.

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

Sidebar

Related Questions

I am trying to convert an existing Android, SQLite database to a multi-platform, SQLite
In my Android Application , I am trying to convert Date/Time to Milliseconds, check
I'm trying to use a switch statement in Android aplication,where I have to check
I have a string in an Android app that I am trying to convert
I am trying to convert an ASP.NET website into a web application project. The
I'm trying to internationalise an Android application. I've a set of strings which I've
Hello I am using an android application and I am trying to figure out
I am using spring android rest template and trying to convert a JSON response
Possible Duplicate: converting pixels to dp in android I'm trying to convert pixels to
I have a simple test application with a GridView containing an array of buttons,

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.