我知道标题有点乱,但问题出在这里……我的目标是检索标题,并使用缩略图 URL 将我的 youtube 频道视频的缩略图绘制到 listView……到目前为止,我有textView 可以正确显示视频标题,但无论如何都无法绘制缩略图.....顺便说一下,我已经正确完成了 json / sqlite 东西类,它们可以正确检索数据,所以我不必担心。 ..唯一困扰我的是缩略图不会显示,imageView在应用程序中显示为空白空间......
这是我的代码,请帮帮我。谢谢
这是活动的创建方法...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] uiBindFrom = { TutListDatabase.COL_TITLE, TutListDatabase.COL_THUMBNAIL };
int[] uiBindTo = { R.id.title, R.id.thumbnail };
getLoaderManager().initLoader(TUTORIAL_LIST_LOADER, null, this);
adapter = new SimpleCursorAdapter(
getActivity().getApplicationContext(), R.layout.list_item,
null, uiBindFrom, uiBindTo,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
adapter.setViewBinder(new MyViewBinder());
setListAdapter(adapter);
}
而这个是把东西放到listView上的私有类...
private class MyViewBinder implements SimpleCursorAdapter.ViewBinder{
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
int viewId = view.getId();
switch(viewId){
case R.id.title:
TextView titleTV = (TextView)view;
titleTV.setText(cursor.getString(columnIndex));
break;
// it is not displaying any thumbnail in app....
case R.id.thumbnail:
ImageView thumb = (ImageView) view;
thumb.setImageURI(Uri.parse(cursor.getString(columnIndex)));
break;
}
return false;
}
}
这是xml布局文件...
<?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:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/thumbnail"
android:layout_width="101dp"
android:layout_height="101dp"
android:src="@drawable/icon" />
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:textSize="24dp" />
</LinearLayout>