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.
should be
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:
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: