我有一个包含多个嵌套LinearLayout和TextView的LinearLayout。
我的主要活动会填充主LinearLayout,
然后我从服务器加载数据,并根据接收到的数据,在一个占位符(LinearLayout)中添加多个布局。
这只是一个简单的新闻页面,我在最初为空的LinearLayout中加载与新闻相关联的图像。
每个图像都有以下信息:标题(TextView)、日期(TextView)、图像(ImageView),所以我实际上做的是:
*请注意,这仅是问题中必要的代码部分,我省略了所有的 try -> catch ... if/else .... 等
public void addImages(JSONArray images){
ViewGroup vg = (ViewGroup) findViewById(R.id.imagesPlaceHolder);
// loop on images
for(int i =0;i<images.length;i++){
View v = getLayoutInflater().inflate(R.layout.image_preview,vg);
// then
I think that here is the problem
ImageView imv = (ImageView) v.findViewById(R.id.imagePreview);
TextView dt = (TextView) v.findViewById(R.id.dateHolder);
TextView ttl = (TextView) v.findViewById(R.id.title);
// then
dt.setText("blablabla");
ttl.setText("another blablabla");
// I think the problem is here too, since it's referring to a single image
imv.setTag( images.getJSONObject(i).getString("image_path").toString() );
// then Image Loader From Server or Cache to the Image View
}
}
上述代码适用于单个图像,但对于多个图像,图片加载器不起作用。我猜这是因为所有的ImageView(多次填充)具有相同的ID。