Question

I am using custom ListView .Its working fine. I am using this ListView for differentiate Read & Unread Messages I pick up message read Id which is 0 for unread message & 1 for read message. My getView() code is following:---

public View getView(int position, View convertView, ViewGroup parent) 
{
    ViewHolder holder;
    if(convertView==null)
    {
        convertView=mInflater.inflate(R.layout.custom_home_list, null);
        holder=new ViewHolder();
        holder.address=(TextView)convertView.findViewById(R.id.person_name);
        holder.body=(TextView)convertView.findViewById(R.id.full_msg);
        holder.date=(TextView)convertView.findViewById(R.id.msg_time);
        convertView.setTag(holder);
    }else
    {
        holder=(ViewHolder)convertView.getTag();
    }
    int size=mArrList.size();
    if ((mArrList != null) || size > 0) 
    {
        if(mArrList.get(position).read.equalsIgnoreCase("1")){
        holder.address.setText(mArrList.get(position).address);
        holder.body.setText(mArrList.get(position).body);
        holder.date.setText(mArrList.get(position).date);
        }else{
            holder.address.setText(mArrList.get(position).address);
            holder.body.setText(mArrList.get(position).body);
            holder.body.setTextColor(mArrList.get(position).color);
            holder.date.setText(mArrList.get(position).date);
        }
    }
    return convertView;
}

here i use this condition for differentiate :-

 if(mArrList.get(position).read.equalsIgnoreCase("1")){
   }

But Position Repeat After 5 items so my condition not working. I have lots of search for this But I am not getting it. Please Help me . Thanks In Advance! Regards Deepanker

Was it helpful?

Solution

In your code you don't explicitely set the color in case of a 'read' state (the first section of your if/else).

It means that if your view is recycled and it was previously used for an 'unread' item, then the color will remain the same.

You need to explicitely say which color you want in both cases, because you cannot know what the initial color is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top