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.

Ant4res
  • 1,217
  • 1
  • 18
  • 36
Gaurav Gupta
  • 1,550
  • 4
  • 18
  • 35

2 Answers2

0

Try the following code:

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: Try to use smart image view http://loopj.com/android-smart-image-view/ to improve performance....

Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44
  • Thanks @praful Bhatnagar : kindly suggest me .Can we make any approach to make list smooth. M already using Lazy Adapter . I think getView is calling everytime and making listview jerky n slow. – Gaurav Gupta Oct 30 '12 at 10:23
0

don't use that loop. Put that list's size in getCount(). It will work properly

mainu
  • 448
  • 2
  • 11