SimpleCursorAdapter与ImageView的和的TextView [英] SimpleCursorAdapter with ImageView and TextView
问题描述
您可以用 ImageView的布局
和的TextView
的行中的 SimpleCursorAdapter
有一个ListView?
can you have a layout with an imageview
and textview
for a row in a SimpleCursorAdapter
with a listview?
这将是布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/bowler_txt"
android:paddingLeft="25dp"
android:textSize="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bowler"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
可以在在SimpleCursorAdapter做一个列表视图?当我需要的图像在ListView我一直使用的自定义arrayadapter,但从来没有与游标。
can it be done in SimpleCursorAdapter with a listview? when I needed images in a listview I always used a custom arrayadapter but never with a cursor.
我将如何设置形象,如果这是可以做到?
How would I set the image if it can be done?
推荐答案
在视图绑定是的ImageView
并没有现有的 ViewBinder
相关 SimpleCursorAdapter.bindView()
电话 setViewImage(ImageView的,字符串)
。
默认情况下,该值将被视为一个的图像资源的。如果该值不能用作图像资源,则该值被用作图像乌里的。
When the view to bind is an ImageView
and there is no existing ViewBinder
associated SimpleCursorAdapter.bindView()
calls setViewImage(ImageView, String)
.
By default, the value will be treated as an image resource. If the value cannot be used as an image resource, the value is used as an image Uri.
如果您需要在其他方面来筛选需要从你的数据库中检索的值 ViewBinder
添加到 ListAdapter
如下:
If you need to filter in other ways the value retrieved from the database you need a ViewBinder
to add to the ListAdapter
as follow:
listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){
/** Binds the Cursor column defined by the specified index to the specified view */
public boolean setViewValue(View view, Cursor cursor, int columnIndex){
if(view.getId() == R.id.your_image_view_id){
//...
((ImageView)view).setImageDrawable(...);
return true; //true because the data was bound to the view
}
return false;
}
});
这篇关于SimpleCursorAdapter与ImageView的和的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!