1

I want to store contact information in an arraylist hash map so that i writ that information in .csv file.

I am able to get contact information but how to make consistency means if i store information "name" in an array and contactno also in array than if any name not contains any contactno then inconsistency would occurs so please tell me how to overcome this.

My code is:

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0) {
    while (cur.moveToNext()) {
        String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
        name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
            //Query phone here.  Covered next
            if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,  null, 
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", 
                    new String[]{id}, null);
                while (pCur.moveToNext()) {
                    // Do something with phones
                    String phoneno = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    //Log.i("phonenos",phoneno);
                } 
                pCur.close();
            }
        }
    }
}
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
ram ji
  • 31
  • 1
  • 6

1 Answers1

0

I don't quite get the question, could you explain it a little better, than I might be able to help.

You want 2 Hashmaps, 1 with contact his name, one with their number, and then you have problems when a contact hasn't got a number or..?

edit:

If you're looking for exporting into an csv, you should see this related topic Android - Generate CSV file from table values

Hope this helps.

Community
  • 1
  • 1
Androider
  • 724
  • 3
  • 12
  • hi androider pls ignore my concept ..actually i dont have much standing about this..do you have any idea about how to store all contactname and contactno in .csv file .means row vice.help would be greatly appreciated.thanks in advance for reply. – ram ji Jul 29 '11 at 04:25
  • I'll edit my answer and hopefully this is what you're looking for. :) – Androider Jul 29 '11 at 06:32