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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:20:58+00:00 2026-06-03T00:20:58+00:00

Cursor searchCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[] {_id,Phone.DISPLAY_NAME}, Phone.DISPLAY_NAME + like ?, new String[]{ %

  • 0
Cursor searchCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
        new String[] {"_id",Phone.DISPLAY_NAME}, Phone.DISPLAY_NAME + " like ?", 
        new String[]{ "%" + cc.get("contactName").toString() + "%"}, null);

startManagingCursor(searchCursor);
while(searchCursor.isAfterLast() == false) {
    final String name = searchCursor.getString(searchCursor.getColumnIndex(Phone.DISPLAY_NAME));
    final String number = searchCursor.getString(searchCursor.getColumnIndex(Phone.NUMBER));
    str =new String[]{name,number};
    ada = new SimpleCursorAdapter(this, R.layout.view_contacts_listview_layout, searchCursor, str, new int[] { R.id.contactName, R.id.contactPhoneNo });
}

lvSearch.setAdapter(ada);

The cursor query running fine only getting problem in simple cursor adapter.

  • 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-03T00:21:01+00:00Added an answer on June 3, 2026 at 12:21 am
    str =new String[]{name,number};
    

    should be

    str = new String[]{Phone.DISPLAY_NAME, Phone.NUMBER};
    

    You are supposed to pass the column names to the SimpleCursorAdapter. Instead, you are passing the column values (ex. 555-555-5555, “john”) as the column names to use

    Additionally, your code can be simplified to:

    Cursor searchCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    new String[] {"_id",Phone.DISPLAY_NAME}, Phone.DISPLAY_NAME + " like ?", 
                     new String[]{ "%" + cc.get("contactName").toString() + "%"}, null);
    
    startManagingCursor(searchCursor);
    str = new String[]{Phone.DISPLAY_NAME, Phone.NUMBER};
    ada = new SimpleCursorAdapter(this,
                                    R.layout.view_contacts_listview_layout, searchCursor,
                                    str, new int[] {
                                            R.id.contactName, R.id.contactPhoneNo });
    

    There’s no reason to access your Cursor before sending it to the SimpleCursorAdapter. It will manage everything you need for you automatically.

    I also noticed that you are also only selecting the contact _ID and DISPLAY_NAME in your query despite trying to access the NUMBER in your SimpleCursorAdapter.. you should modify your projection to include the phone number..
    ex:

    String[] projection = new String[] { BaseColumns._ID, Phone.DISPLAY_NAME, Phone.NUMBER };
    
    Cursor searchCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        projection , Phone.DISPLAY_NAME + " like ?", 
                         new String[]{ "%" + cc.get("contactName").toString() + "%"}, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Cursor smCursor = getContentResolver().query( Uri.parse(content://contact), new String[] { _id, address, body }, address like?,
private Cursor getContacts() { // Run query Uri uri = ContactsContract.Contacts.CONTENT_URI; String[] projection =
I am trying this Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); Cursor cursor1
Cursor cursor = resolver.query( Data.CONTENT_URI, DataQuery.PROJECTION, DataQuery.SELECTION, new String[] {String.valueOf(rawContactId)}, null); With PROJECTION being:
Cursor findNormalItems = db.query(items, columns, type=?, new String[] { onSale }); I want to
public Cursor fetchTimetable() { return mDb.query(DATABASE_TABLE_TIMETABLE, new String[] {TIMETABLE_ROWID, TIMETABLE_MODULECODE, TIMETABLE_MODULENAME, TIMETABLE_ROOM, TIMETABLE_LECTURER, TIMETABLE_TIME},
Cursor mCursor = mDb.query(true, CUSTOMER_TABLE_NAME, new String[] {GENERIC_ID_KEY, ADDRESS_KEY, PHONE_KEY, EMAIL_KEY,CUSTOMER_NAME_KEY}, GENERIC_ID_KEY + =
From my main.java: Cursor c = db.getDue(); String[] columns = new String[] { _id,
Cursor c = managedQuery(People.CONTENT_URI,null,null,null,People.NAME); String[] cols = new String[]{People.NAME}; int[] views = new int[]{android.R.id.text1};
Having this line Cursor c = db.rawQuery(PRAGMA table_info(?), new String[] {tableName}); and getting this:

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.