현재 SQLiteDatabase
에 저장된 연락처 목록을 표시하려고합니다. 이전에 ContactsContract.Contacts.PHOTO_THUMBNAIL_URI
을 검색하여 데이터베이스 행의 BLOB
열에 byte[]
의 형식으로 저장했습니다.ViewBinder가있는 SimpleCursorAdapter로 SQLite BLOB 열
지금 내가 MyBinderView
클래스 Bitmaps
로 디코딩하여, 다시 썸네일을 추출하기 위해 노력하고있을 때, 그림이 표시되지 않습니다, 대신 나는 빈 공간 (기본 이미지, ic_launcher
제대로 보여됩니다)를 참조하십시오. 내 ListView
행 레이아웃 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="1dp">
<ImageView
android:id="@+id/thumbnail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="50dp"
android:layout_marginRight="1dp"
android:src="@drawable/ic_launcher"/>
<TextView
android:id="@+id/email"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"/>
</LinearLayout>
ListFragment
클래스 : 사진에 대한
//DataBaseHelper.PHOTO contains a BLOB fetched from sqlite database
//DataBaseHelper.NAME is a String (no problem here)
String[] from = { DataBaseHelper.PHOTO, DataBaseHelper.NAME };
int[] to = new int[] { R.id.thumbnail, R.id.email };
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Give some text to display if there is no data. In a real
// application this would come from a resource.
setEmptyText("No E-mail buddies found");
// We have a menu item to show in action bar.
// setHasOptionsMenu(true);
contacts = new DataBaseHelper(getActivity());
contacts.open();
// Create an empty adapter we will use to display the loaded data.
mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.contacts,
null, from, to);
mAdapter.setViewBinder(new MyViewBinder());
setListAdapter(mAdapter);
// Start out with a progress indicator.
setListShown(false);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
getLoaderManager().initLoader(0, null, this);
}
ViewBinder
클래스가 올바르게 삽입되는 :
public class MyViewBinder implements ViewBinder{
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
// TODO Auto-generated method stub
int viewId = view.getId();
Log.i("ViewBinder: view", Integer.toString(viewId));
Log.i("ViewBinder: name",cursor.getString(2));
Log.i("ViewBinder: email",cursor.getString(3));
Log.i("ViewBinder: photo",cursor.getBlob(4)==null?"NO Photo":"Has photo");
switch(viewId){
case R.id.thumbnail:
ImageView picture = (ImageView) view;
byte[] blob = cursor.getBlob(columnIndex);
if(blob!=null){
picture.setImageBitmap(
BitmapFactory.decodeByteArray(blob, 0, blob.length)
);
}
else
picture.setImageResource(R.drawable.ic_launcher);
return true;
}
return false;
}
}
어떤 도움을 주시면 감사하겠습니다.