SimpleCursorAdapter with ImageView and TextView

前端 未结 2 1979
情书的邮戳
情书的邮戳 2020-12-30 09:40

can you have a layout with an imageview and textview for a row in a SimpleCursorAdapter with a listview?

this would be the lay

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 10:28

    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.

    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;
       }
    });
    

提交回复
热议问题