在getView毛刺 [英] Glitches in getView

查看:276
本文介绍了在getView毛刺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示的联系人列表。所有好除了设备有1620联系人,以便列表滚动很慢,甚至有时会挂起。

请帮助我。

我试着用在getView方法的支票 ConvertView!= NULL 但alwayz膨胀同样的观点多次。在此先感谢..

我的code为getView方法: -

 如果(ConvertView == NULL)
        {视图= mInflater.inflate(R.layout.facebookfriend,NULL);
                TextView的名字=(TextView中)view.findViewById(R.id.textView1);
                ImageView的图像=(ImageView的)view.findViewById(R.id.imageView1);
            name.setText(mlist.get(位置)获得(名字));                字符串ID = mlist.get(位置)获得(的ContactID);
                Log.e(ID,+ ID);
                复选框chkbox =(复选框)view.findViewById(R.id.checkBox1);
                chkbox.setOnCheckedChangeListener(新OnCheckedChangeListener(){
                    @覆盖
                    公共无效onCheckedChanged(
                            CompoundButton buttonView,布尔器isChecked){
                        isSelected.set(位置,器isChecked);
                    }
                });                                字符串PHOTOID = mlist.get(位置)获得(PHOTOID);
            Log.e(PHOTOID,+ PHOTOID);
                如果(mlist.get(位置)获得(PHOTOID)!= NULL){
                    Log.e(PHOTOID,+PHOTOID);
                    image.setImageBitmap(loadContactPhoto(ID,mlist.get(位置)获得(PHOTOID)));
            }
        }
    }


解决方案

您可以让列表视图动态地加载数据按要求,请参阅本<一个href=\"http://stackoverflow.com/questions/5764441/use-android-dynamicaly-load-more-items-to-the-listview-need-help\">SO帖子,也应该使用 ViewHolder 以使其更有效率见<一href=\"http://stackoverflow.com/questions/1320478/how-to-load-the-listview-smoothly-in-android\">this.

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

解决方案

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.

这篇关于在getView毛刺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆