0


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();
Preeyah
  • 363
  • 3
  • 16
  • 42
  • you can use a AlertDialog for this. when you retrieve from the database and when you dont get in contactList just show the alert then. – BBdev Sep 06 '12 at 03:28

1 Answers1

0

when you giving the query to sqlite database or contacts table, if your cursor is null OR cursor.getCount() is not > 0 then you can show the alert messege to that contacts or data is not present in the database.

Hope this will help you.

and to alertView use this code:

final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("ALERT");
alertDialog.setMessage("NO DATA FOUND");
alertDialog.setIcon(R.drawable.warning);
alertDialog.setButton("OK",new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        // DO YOUR STUFF ON CLICK OF OK
    }
});
alertDialog.show();
Rushabh Patel
  • 3,052
  • 4
  • 26
  • 58
  • By the way, my codes have two cursors and i'm not sure which cursors I need to use for `cursor.getCount() is not > 0`. I'll post my codes above. – Preeyah Sep 06 '12 at 05:42
  • Hi i want to ask you that if I code this correctly or not as i'm not sure. it's in the onCreate() method:`if(cursor.getCount()>0) { final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("ALERT!"); alertDialog.setMessage("NO Name is Found! D:"); alertDialog.setIcon(R.drawable.warning); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); }` – Preeyah Sep 06 '12 at 06:09
  • and I've declared cursor above onCreate() method - `Cursor cursor;` – Preeyah Sep 06 '12 at 06:11
  • if cursor.getCount() > 0 then you should display the contacts or sync whatever you want. when it will be < 0, then you should display alert. – Rushabh Patel Sep 06 '12 at 06:15
  • If someone gives you time to answer your question, you should give response to their answers how they are helpful to your questions. – Rushabh Patel Sep 06 '12 at 06:29