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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:31:24+00:00 2026-05-31T03:31:24+00:00

my question seems silly but it makes me headache by below code. Below code

  • 0

my question seems silly but it makes me headache by below code. Below code print contactId and telephone number to Screen.

It works well, but something I need to know more clearer:

 ContentResolver solver = getContentResolver();
            String mess="";

            Cursor cursor = solver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
            while (cursor.moveToNext()){
                String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                mess = mess + "ID: "+contactId+"\n";

                Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
                while (phones.moveToNext()) { 
                     String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));    
                     mess = mess + phoneNumber + "\n";
                  } 
            }

The thing I don’t know is this line of above code:

Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);

As in Android Development about third parameter:

selection : A filter declaring which rows to return, formatted as an
SQL WHERE clause (excluding the WHERE itself). Passing null will
return all rows for the given URI.

So, as this defination, CONTACT_ID acts as “A ROW”. (because it filter which row to return),

but as this line, CONTACT_ID acts as “A COLUMN”:

String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));

Please explain for me this point.

thanks 🙂

  • 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-31T03:31:25+00:00Added an answer on May 31, 2026 at 3:31 am

    It’s a column (declared like this INTEGER PRIMARY KEY AUTOINCREMENT). In:

    Cursor phones = getContentResolver().query( 
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                        null, 
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, 
                        null, null);
    

    you query the ContentProvider but use the _ID column to filter the results. You are saying: “I want the rows from the ContentProvider where in the column _ID I find only the value contactId“. In:

    String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
    

    _ID is used to get the column index integer(to get the values from that column) so you don’t have to use simple numbers like 0, 1, 2 and possible avoid mistakes.

    Edit:
    The second parameter(also referred as projection) represents the columns of data that you want to retrieve from the provider(null = get all columns). You could look at the second parameter as a filter, you only get those column that you specified in the array(for example maybe you don’t want several columns because you will not use them, so for the second parameter you set a string array with the columns that you do want and omit the ones that you don’t need). The third parameter filter the rows, the second parameter filter the columns you retrieved()

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

Sidebar

Related Questions

My question seems really silly. But I really headache with this question. For example
This seems to be a silly question but, I have to read some data
This seems like a silly question but I would really like your comments and
This might sound like a silly question but how would I make this code
This question seems silly. But I'm new to javascript and sencha touch. Can I
Hey Everyone, This question seems really silly to me, but I can't for the
I am sorry if it seems a silly question to you, but I have
I feel kind of silly asking this question as it seems really simple, but
This seems like a silly question but I can't seem to get this working.
This might seems silly question but for me it is annoying. I have installed

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.