1

I am showing the list of contacts .All good except that device has 1620 contacts so list is scrolling very slow and even sometimes get hangs.

Please help me out.

I tried using a check in getView method for ConvertView!=null but it alwayz inflate same view many times. thanks in advance..

My code for getView method:-

if(ConvertView==null)
        {   view= mInflater.inflate(R.layout.facebookfriend, null);
                TextView name=(TextView)view.findViewById(R.id.textView1);
                ImageView image=(ImageView)view.findViewById(R.id.imageView1);
            name.setText(mlist.get(position).get("name"));

                String Id=mlist.get(position).get("contactId");
                Log.e("Id",""+Id);
                CheckBox chkbox= (CheckBox)view.findViewById(R.id.checkBox1);
                chkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(
                            CompoundButton buttonView, boolean isChecked) {
                        isSelected.set(position, isChecked);
                    }
                });

                                String photoid=mlist.get(position).get("photoId");
            Log.e("photoid",""+photoid);
                if(mlist.get(position).get("photoId")!=null){
                    Log.e("photoid",""+"photoid");
                    image.setImageBitmap(loadContactPhoto(Id, mlist.get(position).get("photoId")));
            }
        }
    }
Barak
  • 16,318
  • 9
  • 52
  • 84
LuminiousAndroid
  • 1,557
  • 4
  • 18
  • 28

2 Answers2

1

Use ViewHolder pattern for effecient ListView. Here is a detailed tutorial about this. Try to implement this in you app and let us know if it helps.

Efficient ListView’s in Android: View Holder Pattern

Shaiful
  • 5,643
  • 5
  • 38
  • 41
0

you can make the listview to load the data dynamically as per the requirement, see this SO post, also you should use ViewHolder to make it more efficient, see this.

Community
  • 1
  • 1
Eight
  • 4,194
  • 5
  • 30
  • 51
  • if (ConvertView == null) { holder = new ViewHolder(); ConvertView= mInflater.inflate(R.layout.facebookfriend, null); holder.name = (TextView)ConvertView.findViewById(R.id.textView1); – LuminiousAndroid Jun 05 '12 at 15:12
  • holder.imageView =ImageView)ConvertView.findViewById(R.id.imageView1); holder.chkbox= (CheckBox)ConvertView.findViewById(R.id.checkBox1); ConvertView.setTag(holder);} else { holder = (ViewHolder) ConvertView.getTag();} holder.name.setText(mlist.get(position).get("Name").toString()); holder. chkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Override public void onCheckedChanged( – LuminiousAndroid Jun 05 '12 at 15:13
  • CompoundButton buttonView, boolean isChecked) {isSelected.set(position, isChecked); Log.e("position"+position,""+isChecked); } }); String Id=mlist.get(position).get("Contactid").toString(); Log.e("Id","--------------"+Id); if(mlist.get(position).get("Photoid")!=null){ Log.e("photoid",""+"photoid"); holder.imageView.setImageBitmap(loadContactPhoto(Id, mlist.get(position).get("Photoid"))); } } – LuminiousAndroid Jun 05 '12 at 15:13
  • Sorry i dun kn again how to write code that's y i put it in three comments Please help !! – LuminiousAndroid Jun 05 '12 at 15:14
  • @Kabir121 pls post the code as another question, so that me and others can help you. – Eight Jun 05 '12 at 15:27
  • Hey abhinav thanks Here is new link.. [link](http://stackoverflow.com/questions/10908866/glitches-in-adapters-getview-method) – LuminiousAndroid Jun 06 '12 at 06:04