hello everyone,
i want to show each number for a single contact in a list.
i could access only one number from the contact i.e. first number
only.
want to show the home, mobile, etc numbers...
can anyone please help me out ...
following is my code snippet...
and thanks in advance......
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sl = new SaveList(this);
cur = managedQuery(People.CONTENT_URI, null, null, null,null);
list = new ArrayList<String>();
ids = new ArrayList<String>();
// contactMap =new HashMap<String, String>();
if (cur.moveToFirst()) {
int nameColumn = cur.getColumnIndexOrThrow(People.NAME);
int phoneColumn =
cur.getColumnIndexOrThrow(People.NUMBER);
String name = "", phoneNumber = "";
do {
name = cur.getString(nameColumn);
phoneNumber = cur.getString(phoneColumn);
// System.out.println("Name "+ name +"Ph
"+phoneNumber);
// contactMap.put(name, phoneNumber);
if (phoneNumber != null &&
!phoneNumber.equals("")) {
name = name + "\n" + phoneNumber;
list.add(name);
ids.add("" + cur.getInt(0));
}
} while (cur.moveToNext());
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
list);
sl.setOnItemClickListener(this);
sl.setAdapter(adapter);
sl.setId(0);
}
setContentView(sl);
}
public void onItemClick(AdapterView l, View v, int position, long id)
{
cur.moveToFirst();
long personId = Integer.parseInt(ids.get((int)
position));
//System.out.println("person id" + personId);
Uri personUri =
ContentUris.withAppendedId(People.CONTENT_URI,
personId);
// So now the URL looks like:
content://contacts/people/_id(where
// the actual id of the record is here)
Uri phoneUri = Uri.withAppendedPath(personUri,
People.Phones.CONTENT_DIRECTORY);
//People.ContactMethods.CONTENT_DIRECTORY);
// Now the URL looks like:
content://contacts/people/_id/phones
// (where phones is literally "phones")
// Now get all the phone numbers for this contact
Cursor phonesCursor = managedQuery(phoneUri, null, null,
null,null);
phonesCursor.moveToFirst();
lis = new ArrayList<String>();
String ss;
System.out.println("column count" +
phonesCursor.getColumnCount());
System.out.println("row count" +
phonesCursor.getCount());
phonesCursor.moveToFirst();
String names[] = phonesCursor.getColumnNames();
for (int i = 0; i < names.length; i++) {
System.out.println(i+ " is "+names[i]
+ " = " + phonesCursor.getString(i));
}
ss = "" + phonesCursor.getString(3);
if (ss != null && !ss.equals(""))
lis.add(ss);
ss = "" + phonesCursor.getString(16);
if (ss != null && !ss.equals(""))
lis.add(ss);
adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
lis);
sl.setId(1);
sl.setOnItemClickListener(this);
sl.setAdapter(adapter1);
sl.invalidate();
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---