我使用毕加索来加载从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特定图像,而不是最后一个。
请发送完整代码 –
+1。您需要发布循环的完整代码。 – greenapps
已更新并添加了整个功能,它已在onPostExecute中调用 –