문제

In my case list view on scroll showing duplicate cells. Not working properly. this is my code in getView()

    if(convertView == null)
        {
            LayoutInflater infalInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.contact_cell, null);
        }

        try {
            if(contacts.getContacts().get(position).getPhone() != null) {
                ImageView contactIcon = (ImageView) convertView.findViewById(R.id.pic);
                TextView contactName = (TextView) convertView.findViewById(R.id.name);
                contactName.setText(contacts.getContacts().get(position).getDisplayName());
                contactIcon.setImageBitmap(contacts.getContacts().get(position).getThumbNail());
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return convertView;
도움이 되었습니까?

해결책

Add this to yuor getView() method

if(contacts.getContacts().get(position).getPhone() != null) {
    ImageView contactIcon = (ImageView) convertView.findViewById(R.id.pic);
    TextView contactName = (TextView) convertView.findViewById(R.id.name);
    contactName.setText(contacts.getContacts().get(position).getDisplayName());
    contactIcon.setImageBitmap(contacts.getContacts().get(position).getThumbNail());
}else{
    ImageView contactIcon = (ImageView) convertView.findViewById(R.id.pic);
    TextView contactName = (TextView) convertView.findViewById(R.id.name);
    contactName.setText("");
    contactIcon.setImageBitmap(null);
}

It happens when getPhone() returns null and convertView does not update.

다른 팁

I guess this is your problem:

if(contacts.getContacts().get(position).getPhone() != null)

What are you doing if the phone is null? You are leaving the old content inside the view. You should provide some placeholders for this condition. Same thing for the exception. And btw why are you catching an exception there?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top