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

  • Home
  • SEARCH
  • 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 7070825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:36:47+00:00 2026-05-28T05:36:47+00:00

I’m a little confused about how to use the cursor to access the data

  • 0

I’m a little confused about how to use the cursor to access the data that I need using the CursorLoader model. I was able to use a SimpleCursorAdapter and pass the cursor to the swapCursor method of the adapter within the onLoadFinished method that you have to implement as follows.

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    facilityAdapter.swapCursor(cursor);

}

Now I need to query the database and based on the number of rows returned display an integer. How do I access this information? There is some information that I would like to store (the _id) of certain rows selected so that I can bundle it up and pass it to the next activity, because the id is a foreign key in other database tables and I’ll need to to query the database. On the android developer site I’ve seen that there are accesor methods to the cursor class such as cursor.getInt, cursor.getString, etc etc, should I be using these to access the data that I am after.

  • 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-28T05:36:48+00:00Added an answer on May 28, 2026 at 5:36 am

    It seems like you have two questions here… so I’ll answer them both. Correct me if I misunderstood your question…

    1. To get the number of rows in the table, you perform a simple query as follows:

      Cursor cur = getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
      int numColumns = cur.getCount();
      cur.close();
      
    2. Retrieving the id of a selected item is actually very simple, thanks to Android adapters. Here’s an example that outlines how you might pass an id to another Activity (for example, when a ListView item is clicked).

      public class SampleActivity extends Activity implements
              LoaderManager.LoaderCallbacks<Cursor> {
      
          // pass this String to the Intent in onListItemClicked()
          public static final String ID_TAG = "id_tag";
      
          private SimpleCursorAdapter mAdapter;
      
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
      
              /* setup layout, initialize the Loader and the adapter, etc. */
      
              setListAdapter(mAdapter);
          } 
      
          @Override
          public void onListItemClick(ListView l, View v, int position, long id) {
              final Intent i = new Intent(getApplicationContext(), NewActivity.class);
              i.putExtra(ID_TAG, id);
              // pass the id to NewActivity. You can retrieve this information in
              // the Activity's onCreate() method with something like:
              // long id = getIntent().getLongExtra(SampleActivity.ID_TAG, -1);
              startActivity(i);
          }
      }
      

      You’ll have to create a URI yourself to query the foreign database. This can be done with something like:

      Uri uri = Uri.withAppendedPath(CONTENT_URI, String.valueOf(id));
      

      where CONTENT_URI is the appropriate CONTENT_URI for your ContentProvider.

    Let me know if that helps!

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.