I get it. If someone had the same problem, here is how I did it:
In an activity that extends ListActivity:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Cursor names = getNamesAndPictures(); names.moveToFirst(); ListAdapter adapter = new MySimpleCursorAdapter(this, R.layout.contacts, names, new String[] {Phones.NAME, Phones.NUMBER}, new int[] { R.id.Nombre, R.id.Numero}); setListAdapter(adapter); startManagingCursor(names); Log.i(DEBUG_TAG, "Mi numero: " + miNumeroTelefono()); } public Cursor getNamesAndPictures(){ String[] projection = new String[] { Phones.NUMBER, Phones.PERSON_ID, People.NAME, People._ID }; String selection = Phones.NAME + "!='null'"; String sortOrder = Phones.NAME + " COLLATE LOCALIZED ASC"; Cursor cursor = managedQuery(Phones.CONTENT_URI, projection, selection, null, sortOrder); return cursor; }
In user adapter:
public class MySimpleCursorAdapter extends SimpleCursorAdapter { ... @Override public void bindView(View view, Context context, Cursor cursor) { ImageView imageView = (ImageView) view.findViewById(R.id.Foto); int id = cursor.getColumnIndex(Phones.PERSON_ID); Uri uri = ContentUris.withAppendedId(Phones.CONTENT_URI, cursor.getLong(id)); String uriPhoto = uri.toString(); String uriPeople = uriPhoto.replace("phones", "people"); Uri uriFinal = Uri.parse(uriPeople); Bitmap bitmap = People.loadContactPhoto(context, uriFinal, R.drawable.avatar02, null); imageView.setImageBitmap(bitmap); super.bindView(view, context, cursor); } }
source share