【发布时间】:2013-02-03 01:14:49
【问题描述】:
我有一个带有许多嵌套 LinearLayouts 和 TextViewss 的 LinearLayout
我的主要活动膨胀了主要的 LinearLayout,
然后我从服务器加载数据并根据接收到的数据,在占位符中添加多个布局 (LinearLayout)
这是一个简单的新闻页面,我在其中加载与新闻相关的图像并将其放置在最初为空的 LinearLayout 中。
每个图像都有以下信息:Title(TextView)、Date(TextView)、Image(ImageView) 所以我实际做的是以下内容:
*请注意,这只是我将所有 try -> catch ... if/else ....etc 元素化的问题中的基本代码
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
【问题讨论】:
-
您有什么理由不使用列表视图吗?
-
是的,我在 Scrollview 中有一个 LinearLayout,顶部有一些 TextView,然后我有很多 ImageView,甚至是 Video Holders,ListView 将在 ScrollView 中有自己的滚动,它会不利于可用性(如果我是对的)
标签: android android-layout android-view android-inflate