0

I'm using the following code to make a custom listview. I have to show image dynamically, so all the images are added to this in Linearlayout. The problem is that these dynamic images add multiple times. Below is the code of my 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);     

            }
        }

Kindly suggest me on that issue. Thanks in Advance.

4

2 回答 2

0

试试下面的代码:

LinearLayout fbpiclayout = null;

        if (convertView == null)
            vi = inflater.inflate(R.layout.popular_event_list, null);

         fbpiclayout = (LinearLayout) vi
                .findViewById(R.id.fbpic_layout);

          //if the convertView was not null it would have the child view you added the 
          //  last time liner layout was used. So remove the added child view.  
          fbpiclayout.removeAllViews();

        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);     

            }
        }

EDIT1:尝试使用智能图像视图http://loopj.com/android-smart-image-view/来提高性能....

于 2012-10-30T09:27:23.847 回答
0

不要使用那个循环。将该列表的大小放入 getCount() 中。它会正常工作

于 2012-10-30T09:29:18.297 回答