【发布时间】:2012-10-30 09:17:58
【问题描述】:
我正在使用以下代码来制作自定义listview。我必须动态显示图像,因此所有图像都在 Linearlayout 中添加到此。问题是这些动态图像添加了多次。下面是我getView()的代码。
LinearLayout fbpiclayout = null;
if (convertView == null)
vi = inflater.inflate(R.layout.popular_event_list, null);
fbpiclayout = (LinearLayout) vi
.findViewById(R.id.fbpic_layout);
ArrayList<String> list= mDbManager
.getAllValuesComingSoonFriendList(facebookEventList
.get(position).getEventId());
int height = 0;
for(int i=0;i<list.size();i++)
{
if(i<3)
{
String friendPics = "http://graph.facebook.com/"
+ list.get(i)
+ "/picture?type=large";
Log.d("Friends","list no "+i+" "+mDbManager
.getFacebookFriendName(list.get(i)));
ImageView fbFriendimage = new ImageView(getActivity());
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
vp.setMargins(3, 0, 3, 3);
fbFriendimage.setLayoutParams(vp);
fbFriendimage.setAdjustViewBounds(true);
fbFriendimage.getLayoutParams().height = height;
fbFriendimage.getLayoutParams().width = width_iv;
fbFriendimage.setScaleType(ImageView.ScaleType.CENTER_CROP);
// image.setImageBitmap(bm);
imageLoader.DisplayImage(friendPics, fbFriendimage);
fbpiclayout.addView(fbFriendimage, vp);
}
}
请就这个问题向我提出建议。 提前致谢。
【问题讨论】:
-
多次是什么意思?为什么在 getView 方法中使用循环?
-
删除 if(convertView == null)
-
在每个列表项中,我必须添加多个图像。这些图像 url 存储在列表中。就像列表位置一样,我有 3 张图片。 M 将这 3 个图像循环添加到线性布局。多次意味着,在我的列表中只有 3 张图像,但线性布局在该列表位置显示 6 或 9 张图像。每次 getView 调用它都没有增加。
-
@Manikandan 它的作品,但它使列表视图生涩和缓慢。对此有何建议?
-
@Gaurav 使用lazyLoading,您的列表视图可以正常工作。
标签: android list listview baseadapter