2014-06-30 29 views
0

我使用畢加索來加載從webservice解析的幾個圖像...問題是,我有多個項目,但只有最後一個項目被下載並加載到所需的視圖...這裏是我的代碼的一部分處理該填充物品:畢加索for循環加載只有一個圖像

public void populate_jobs(ArrayList<RowItem> jobs) 
{ 
    LinearLayout ll_parent = (LinearLayout) findViewById(R.id.list_container); 
    for(int i = 0;i < jobs.size();i+=3) 
    { 
     RowItem item_first = jobs.get(i); 
     _items.add(item_first); 
     RowItem item_second = null; 
     RowItem item_third = null; 
     if(jobs.size() > i+1) 
     { 
      item_second = jobs.get(i+1); 
      _items.add(item_second); 
     } 
     if(jobs.size() > i+2) 
     { 
      item_third = jobs.get(i+2); 
      _items.add(item_third); 
     } 
     LinearLayout ll = new LinearLayout(this); 
     LinearLayout.LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
     ll.setGravity(Gravity.CENTER); 
     ll.setLayoutParams(lp); 
     ll.setOrientation(LinearLayout.HORIZONTAL); 

     LinearLayout.LayoutParams lp_btn = new LayoutParams(convertToPx(100), convertToPx(100)); 
     lp_btn.setMargins(convertToPx(5), convertToPx(5), convertToPx(5), convertToPx(5)); 
     ImageButton btn_first = new ImageButton(this); 
     btn_first.setLayoutParams(lp_btn); 
     btn_first.setId(item_first.getId()); 

     //getImagesAsyncTask img_first = new getImagesAsyncTask(item_first.getImageSrc(), btn_first, this); 
     //img_first.execute(); 
     Picasso.with(this) 
     .load(item_first.getImageSrc().replace("~", URL_IAMGES)) 
     .fit() 
     .into(btn_first, new Callback() { 

      @Override 
      public void onSuccess() { 
       String s = "asd"; 
      } 

      @Override 
      public void onError() { 
      } 
     }); 
     btn_first.setOnClickListener(this); 
     ll.addView(btn_first); 

     if(item_second != null) 
     { 
      ImageButton btn_second = new ImageButton(this); 
      btn_second.setLayoutParams(lp_btn); 
      btn_second.setId(item_second.getId()); 

      //getImagesAsyncTask img_second = new getImagesAsyncTask(item_second.getImageSrc(), btn_second, this); 
      //img_second.execute(); 

      Picasso.with(this) 
      .load(item_second.getImageSrc().replace("~", URL_IAMGES)) 
      .fit() 
      .into(btn_second, new Callback() { 

       @Override 
       public void onSuccess() { 
        String s = "asd"; 
       } 

       @Override 
       public void onError() { 
       } 
      }); 
      btn_second.setOnClickListener(this); 
      ll.addView(btn_second); 
     } 

     if(item_third != null) 
     { 
      ImageButton btn_third = new ImageButton(this); 
      btn_third.setLayoutParams(lp_btn); 
      btn_third.setId(item_third.getId()); 
      //getImagesAsyncTask img_second = new getImagesAsyncTask(item_third.getImageSrc(), btn_third, this); 
      //img_second.execute(); 

      Picasso.with(this) 
      .load(item_third.getImageSrc().replace("~", URL_IAMGES)) 
      .fit() 
      .into(btn_third, new Callback() { 

       @Override 
       public void onSuccess() { 
        String s = "asd"; 
       } 

       @Override 
       public void onError() { 
       } 
      } 
       ); 
      btn_third.setOnClickListener(this); 
      ll.addView(btn_third); 
     } 
     ll_parent.addView(ll); 
    } 
} 

我打電話的這個在我的AsyncTask的onPostExecute功能,它負責從web服務獲取JSON數據循環的功能。所有圖像的圖像源內容都是正確的,可以通過瀏覽器訪問,原因可能是什麼?在此先感謝

編輯:因爲我檢查它似乎只加載1特定圖像,而不是最後一個。

+0

請發送完整代碼 –

+1

+1。您需要發佈循環的完整代碼。 – greenapps

+0

已更新並添加了整個功能,它已在onPostExecute中調用 –

回答

0

好吧,我發現它,網址中包含空格(感謝設計師誰創造的圖像),所以因爲畢加索未能下載圖像,我不知道他們不處理的空間網址。無論如何感謝greenapps的幫助。

+0

Url對url進行編碼。或用%20替換空格。 – greenapps

+0

yea已經這樣做了,謝謝你的一步一步的幫助 –

1

Url對網址進行編碼。或用%20替換空格。