getView中出现故障

时间:2012-06-05 11:30:35

标签: android android-listview contacts adapter

我正在显示联系人列表。除了该设备有1620个联系人之外,所以很好,所以列表滚动非常慢,甚至有时会挂起。

请帮帮我。

我尝试使用ConvertView!=null的getView方法检查,但它总是多次向同一视图充气。提前谢谢..

我的getView方法代码: -

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

2 个答案:

答案 0 :(得分:1)

使用ViewHolder pattern提高效率ListView。这是一个关于此的详细教程。 尝试在你的应用程序中实现这一点,并告诉我们它是否有帮助。

Efficient ListView’s in Android: View Holder Pattern

答案 1 :(得分:0)

您可以使列表视图按照要求动态加载数据,请参阅此SO post,同时您应该使用ViewHolder提高效率,请参阅this

相关问题