2013-07-02 96 views
0

我想要做的是將與數據庫中的記錄相關聯的圖片文件加載到ListView中。下面的代碼會將數據庫中的記錄加載到列表視圖中,但是當我使用ImageView並嘗試將關聯的文件加載到ImageView中時。我收到以下錯誤:如何將圖像加載到從數據庫加載數據的列表視圖中?

"The method decodeResource(Resources, int) in the type BitmapFactory is not applicable for the arguments (Resources, Bitmap)" 

任何幫助,你可以給我將不勝感激。謝謝!

private void displayListView() {  
    setContentView(R.layout.activity_photo_review); 
    root = Environment.getExternalStorageDirectory().toString(); 
    //  File myDir = new File(root + "/req_images/"); 
    //Get Assessment Name from Global Variable 
    String CustName = ((GlobalVariables) this.getApplication()).getSomeVariable(); 

    camHelper = new DBCamera(this); 
    camHelper.open();  
    Cursor cursor = camHelper.fetchDataByAssessment(CustName);  

    String FileName = cursor.getString(cursor.getColumnIndexOrThrow("file_name")); 

    String image = root + "/req_images/" + FileName; 
    Bitmap myBitmap = BitmapFactory.decodeFile(image); 
    //  ImageView iv = (ImageView) findViewById (R.id.imageView1); 
    //  iv.setImageBitmap(myBitmap); 

    // The desired columns to be bound 
    String[] columns = new String[] {  
      DBCamera.KEY_NAME,  
      DBCamera.KEY_DESCLUBSTORAGE,  
      DBCamera.KEY_DESCLUBDIS,  
      DBCamera.KEY_DESCLUBSCHED,  
      DBCamera.KEY_DESCTRAINING,  
      DBCamera.KEY_DESCOILSAMP,  
      DBCamera.KEY_DESCEQUIPMENT,  
      DBCamera.KEY_DESCMISCEQUIP,  
      DBCamera.KEY_DESCPRODUCTLEAK,  
      DBCamera.KEY_DESCHYDRAULICSYS,  
      DBCamera.KEY_DESCCENTRALLUBSYS,  
      DBCamera.KEY_DESCMOBILEEQUIP,  
      DBCamera.KEY_DESCHOUSEKEEPING,  
      DBCamera.KEY_DESCPOTENTIALENVIR,  
      DBCamera.KEY_DESCCONCERNS,  
      DBCamera.KEY_DESCSAFETY,  
      DBCamera.KEY_DESCCHECKBOX1,  
      DBCamera.KEY_DESCCHECKBOX2,  
      DBCamera.KEY_DESCCHECKBOX3,  
      DBCamera.KEY_DESCCHECKBOX4,  
      DBCamera.KEY_DESCCHECKBOX5,  
      DBCamera.KEY_DESCCHECKBOX6,  
      DBCamera.KEY_DESCCHECKBOX7, 
    };  
    // the XML defined views which the data will be bound to 
    int[] to = new int[] { 
      //Load each picture 
      //this is where I get the error "The method decodeResource(Resources, int) in the type BitmapFactory is not applicable for the arguments (Resources, Bitmap)" 
      R.id.imageView1.setImageBitmap(BitmapFactory.decodeResource(getResources(), myBitmap)), 


      R.id.code,  
      R.id.name, 
      R.id.manufacturer,  
      R.id.visc40,  
      R.id.visc100,  
      R.id.viscindex,  
      R.id.den15c,  
      R.id.name1,  
      R.id.visctext,  
      R.id.baseoiltype,  
      R.id.name2,  
      R.id.baseoil,  
      R.id.additives,  
      R.id.name3,  
      R.id.otheradditives,  
      R.id.thickener,  
      R.id.nlgi,  
      R.id.name4,  
      R.id.comments,  
      R.id.packages,  
      R.id.area, 
      R.id.usage, 
      R.id.name5,  
    };  
    // create the adapter using the cursor pointing to the desired data  
    //as well as the layout information 
    dataAdapter = new SimpleCursorAdapter(  
      this, R.layout.activity_photo_review_info, cursor, columns, to, 0);  

    ListView listView = (ListView) findViewById(R.id.listView1); 
    // Assign adapter to ListView 
    listView.setAdapter(dataAdapter); 

    //SetOnItemClickListener for the ListView 
    listView.setOnItemClickListener(new OnItemClickListener() { 
    @Override 
    public void onItemClick(AdapterView<?> listView, View view,  
      int position, long id) {  

     // Get the cursor, positioned to the corresponding row in the result set  
     Cursor cursor = (Cursor) listView.getItemAtPosition(position);  
     // Get the Customer Name from this row in the database.  
     String ProdName = cursor.getString(cursor.getColumnIndexOrThrow("ProductName")); 
     String Area = cursor.getString(cursor.getColumnIndexOrThrow("Area")); 

     Intent intent = new Intent(PhotoReview.this, ProductInput.class); 
     intent.putExtra("ProdName", ProdName); 
     intent.putExtra("Area", Area); 
     startActivity(intent); 

     //   Toast.makeText(getApplicationContext(), Area, Toast.LENGTH_SHORT).show();  

     } 

    }); 
} 

回答

0

decodeResource()預計資源ID傳遞參數,而不是Bitmap,這是你現在通過什麼。

0

你試過R.id.imageView1.setImageBitmap(myBitmap)

相關問題