【问题标题】:Glitches in getViewgetView 中的故障
【发布时间】:2023-04-08 02:53:01
【问题描述】:

我正在显示联系人列表。除了该设备有 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")));
            }
        }
    }

【问题讨论】:

    标签: android android-listview contacts adapter


    【解决方案1】:

    使用ViewHolder pattern 获得有效的ListView。这是有关此的详细教程。 尝试在您的应用中实现此功能,如果有帮助,请告诉我们。

    Efficient ListView’s in Android: View Holder Pattern

    【讨论】:

      【解决方案2】:

      您可以根据需要使列表视图动态加载数据,请参阅SO post,也应使用ViewHolder 使其更高效,请参阅this

      【讨论】:

      • if (ConvertView == null) { holder = new ViewHolder(); ConvertView= mInflater.inflate(R.layout.facebookfriend, null); holder.name = (TextView)ConvertView.findViewById(R.id.textView1);
      • 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());持有者。 chkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Override public void onCheckedChanged(
      • CompoundButton buttonView, boolean isChecked) {isSelected.set(position, isChecked); Log.e("位置"+位置,""+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"))); } }
      • 对不起,我又不知道怎么写代码了,我把它放在三个 cmets 中请帮忙!!
      • @Kabir121 请将代码作为另一个问题发布,以便我和其他人可以帮助您。
      猜你喜欢
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      • 2020-04-18
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多