I want to show "Contact name" and "contact number" in a list. But my code repeats "contact name" depends on how many number or other attributes (i.e. email id ) associated with that particular Name. For example . In Contact directory contact list as.. Pankaj Kumar and numbers 000000-000 and 00000-2222. I want output as only Pankaj Kumar and primary_number, but output comes with ( Pankaj kumar and number 000000-000) and its repeat with ( Pankaj kumar and number 00000-2222).
How can I solve it..
My code is as below ..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// We'll define a custom screen layout here (the one shown above), but
// typically, you could just use the standard ListActivity layout.
setContentView(R.layout.contacts_list_item);
Cursor mCursor = getContentResolver().query(Data.CONTENT_URI,
null, // projection
null, // selection
null, // selectionArgs
Data.DISPLAY_NAME); // sortOrder
startManagingCursor(mCursor);
// Now create a new list adapter bound to the cursor.
// SimpleListAdapter is designed for binding to a Cursor.
contactAdapter = new SimpleCursorAdapter(
this, // Context.
android.R.layout.two_line_list_item, // Specify the row template to use (here, two columns bound to the two retrieved cursor rows).
mCursor, // Pass in the cursor to bind to.
new String[] {Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}, // Array of cursor columns to bind to.
new int[] {android.R.id.text1, android.R.id.text2}); // Parallel array of which template objects to bind to those columns.
// Bind to our new adapter.
setListAdapter(contactAdapter);
}