2017-03-17 221 views
0

嗨,大家好,我有一個問題, 我有一個名單,我必須使用reycleview來查看它在列表中,但是當我通過cericare柏去的形象,要做到這一點使用畢加索加載圖像與畢加索

@Override 
public void onBindViewHolder(ViewHolder viewHolder, final int i) { 
    this.viewHolder=viewHolder; 
    if(scheduler.size()>=1){ 
     viewHolder.time.setText(scheduler.get(i).getTime()); 
     viewHolder.data.setText(scheduler.get(i).getData()); 
     viewHolder.delete.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       removeItem(i); 
      } 
     }); 


     String phat=scheduler.get(i).getImageString(); 
     //result paht: content://com.android.providers.media.documents/document/image%3A445 
     Picasso.with(c).load(phat).into(viewHolder.img);//does not display the image 




     viewHolder.img.setOnClickListener(new MyClikListener(i)); 
     viewHolder.time.setOnClickListener(new MyClikListener(i)); 
     viewHolder.data.setOnClickListener(new MyClikListener(i)); 
     viewHolder.card_view_reminder.setOnClickListener(new MyClikListener(i)); 
    } 

} 

我也嘗試在URI中轉換pat但沒有任何結果。 製作調試告訴我onBitmapFailed

+0

什麼問題,應用程序崩潰?或者圖像根本無法加載? –

+0

你有什麼錯誤嗎?要記錄錯誤消息,請使用構建器創建一個Picasso實例。 'Picasso picasso = new Picasso.Builder(c).listener(...)。build()' – csabapap

回答

-1

試試這個

new DownloadImage(yourImageView).execute(URL); 

從後臺進程下載映像創建的AsyncTask

public class DownloadImage extends AsyncTask<String, Void, Bitmap> { 
    CircleImageView bmImage; 

    public DownloadImage(ImageView bmImage) { 
     this.bmImage = (CircleImageView) bmImage; 
    } 

    protected Bitmap doInBackground(String... urls) { 
     String urldisplay = urls[0]; 
     Bitmap mIcon11 = null; 
     try { 
      InputStream in = new java.net.URL(urldisplay).openStream(); 
      mIcon11 = BitmapFactory.decodeStream(in); 
     } catch (Exception e) { 
      Log.d("Error", e.getStackTrace().toString()); 

     } 
     return mIcon11; 
    } 

    protected void onPostExecute(Bitmap result) { 
     bmImage.setImageBitmap(result); 
    } 
} 

它將爲所有工作..

0

使用下面的代碼:

Picasso.with(c).load(new File(phat)).into(viewHolder.imageView); 

希望這會有所幫助。