So I have an old problem: code works fine while is shouldn't. Can anyone guess how is it possible?
I'm showing a list of contacts, with photo thumbnail for each contact. Returned Cursor data does not have any photo thumbnail data, yet thumbnail is shown correctly for each contact.
List item view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/userpic"
android:layout_width="150dp"
android:layout_height="150dp"
android:contentDescription="Userpic"
/>
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:textSize="24sp"
android:padding="12dp"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
The main code
private static class CursorAdapter extends SimpleCursorAdapter {
private static final String[] FROM = new String[]{
Contacts.DISPLAY_NAME_PRIMARY,
Contacts.PHOTO_THUMBNAIL_URI
};
private static final int[] TO = new int[]{
android.R.id.text1,
R.id.userpic
};
public CursorAdapter(Activity activity, Cursor c) {
super(activity, R.layout.contacts_item, c, FROM, TO, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// Here I logged cursor contents and am sure that thumbnail column data is null.
dumpCursorCurrent(cursor);
View view = super.newView(context, cursor, parent);
int columnIndex = cursor.getColumnIndexOrThrow(Contacts.PHOTO_THUMBNAIL_URI);
String thumbnailUriString = cursor.getString(columnIndex);
if (thumbnailUriString != null) {
throw new RuntimeException("Never comes here");
}
return view;
}
}
code that creates Cursor:
ContentResolver contentResolver = getActivity().getContentResolver();
Cursor c = contentResolver.query(
Contacts.CONTENT_URI,
projection,
null,
null,
null
);
So the list has proper photos for each contact that has the photo.
I debugged SimpleCursorAdapter code, and it shouldn't work, it calls imageView.setImageURI(Uri.parse("")), and naturally logs a warning for each row:
09-03 01:47:20.023 27814-27814/me.lazerka.mf.android E/BitmapFactory﹕ Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory) 09-03 01:47:20.023
27814-27814/me.lazerka.mf.android I/System.out﹕ resolveUri failed on bad bitmap uri:
So who sets the proper imageURI for each ImageView, and where does it take it (cursor has null always)?
0 comments:
Post a Comment