I'm working on an app where I've a ListView of contacts' names retrieved from the built-in contacts list. I use ContentProvider to get the names from the built-in contacts list. Plus, I store the names from the ListView into my database table.
I need to synchronize with the built-in contacts list with database table. So, I need to trigger an alert message for the user when there is no match between the DISPLAY_NAME in ContactsContract from the built-in and a name from my table. And, the user will have to manually change the name and I'll have to change the name which is from the table.
How do I do that? i need help with this.
I appreciate any help provided. Any examples and tutorials will be also appreciated.
Thanks.!
UPDATE
ContactsList.java - this is the ListView of contacts retrieved from the android phone's contacts.
BuddyDBAdapter buddyDB = new BuddyDBAdapter(this);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_list);
ListView list = getListView();
setListAdapter(new ArrayAdapter<String> (this, R.layout.contacts_list, R.id.contactName, buddiesList));
Uri allContacts = Uri.parse("content://contacts/people");
Cursor c = managedQuery(allContacts, null, null, null, null);
String[] columns = new String[] {ContactsContract.Contacts.DISPLAY_NAME};
int[] views = new int[] {R.id.contactName};
startManagingCursor(c);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contacts_list, c, columns, views);
this.setListAdapter(adapter);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id)
{
buddyDB.open();
long name_id;
super.onListItemClick(l, v, position, id);
/*String action = getIntent().getAction();
if(Intent.ACTION_VIEW.equals(action))
{
//startActivity(intent);
}*/
//startActivityForResult(new Intent(Intent.ACTION_PICK),PICK_CONTACT);
Cursor c = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
TextView contactName = (TextView) v.findViewById(R.id.contactName);
String NameValue = contactName.getText().toString();
name_id = buddyDB.insertNames(NameValue);
Toast.makeText(getBaseContext(),
"Selected: " + buddiesList[position], Toast.LENGTH_SHORT).show();
buddyDB.close();