tyc*_*czj 9 android listview simplecursoradapter
你有一个带有列表视图的行imageview和textview一行的布局SimpleCursorAdapter吗?
这将是布局
<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>
Run Code Online (Sandbox Code Playgroud)
可以使用listview在SimpleCursorAdapter中完成吗?当我在listview中需要图像时,我总是使用自定义arrayadapter但从不使用光标.
如果可以的话,我该如何设置图像?
Fra*_*amo 24
当要绑定的视图是ImageView并且没有现有的ViewBinder关联SimpleCursorAdapter.bindView()调用时setViewImage(ImageView, String).默认情况下,该值将被视为图像资源.如果该值不能用作图像资源,则该值用作图像Uri.
如果您需要以其他方式过滤从数据库中检索的值,您需要ViewBinder添加到ListAdapter以下内容:
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;
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12775 次 |
| 最近记录: |