SimpleCursorAdapter how to show an image?

前端 未结 1 1966
南旧
南旧 2020-12-06 04:03

I am making an android recipes application where i use a database. In database there is a column named\" \"images\", where i store the name of the file of t

相关标签:
1条回答
  • 2020-12-06 04:28

    You need to set the ViewBinder of the adapter to set the image of the ImageView to the value received from the DB.

        esodaAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
                     @Override
                     public boolean setViewValue (View view, Cursor cursor, int columnIndex){
                         if (view.getId() == R.id.imageView1) {
                             ImageView IV=(ImageView) view;
                             int resID = getApplicationContext().getResources().getIdentifier(cursor.getString(columnIndex), "drawable",  getApplicationContext().getPackageName());
                             IV.setImageDrawable(getApplicationContext().getResources().getDrawable(resID));
                             return true;
                        }
                         return false;
             } 
    
    0 讨论(0)
提交回复
热议问题