Hi group, I still have not been able to get some assistance in retrieving contact data and I could really use the help. Right now, the only thing I can access without any null pointer or cursor out of bounds exceptions being thrown is the contacts display name. Does anyone know how to access a phone number as well as the thumbnail icon associated with a contact? Thanks.
package com.grey.gui; import android.app.ListActivity; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.provider.ContactsContract; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.ListView; import android.widget.TextView; public class MainPage extends ListActivity { private Cursor c; private ContentResolver cr; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); cr = getContentResolver(); c = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null,null); this.setListAdapter(new MyContactsAdapter(this,c)); } @Override public void onListItemClick(ListView l, View v, int position, long id){ super.onListItemClick(l, v, position, id); Intent newIntent = new Intent(Intent.ACTION_MAIN); newIntent.setClass(this, Summary.class); startActivity(newIntent); } private class MyContactsAdapter extends CursorAdapter{ private Cursor mCursor; private Context mContext; private final LayoutInflater mInflater; public MyContactsAdapter(Context context, Cursor cursor) { super(context, cursor, true); mInflater = LayoutInflater.from(context); mContext = context; } private TextView t; @Override public void bindView(View view, Context context, Cursor cursor) { String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); Log.d("Name",name); t = (TextView) view.findViewById(R.id.txtName); if(name != null) t.setText(name); String hasNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); Log.d("hasNumber", hasNumber); // if(hasNumber.equals("1")){ String number = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.NUMBER)); //Log.d("Number", number); //TextView a = (TextView) view.findViewById(R.id.phoneNumber); //a.setText(number); // } /*ImageView i = (ImageView) view.findViewById(R.id.icon); byte[] img = cursor.getBlob(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID)); Bitmap b = BitmapFactory.decodeByteArray(img, 0, img.length); i.setImageBitmap(b);*/ } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { final View view = mInflater.inflate(R.layout.main, parent, false); return view; } } } -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en To unsubscribe, reply using "remove me" as the subject.