2

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

Deepanker Chaudhary
  • 1,694
  • 3
  • 15
  • 35
  • seems it's as it should be - ListView sometimes calls getView() with the same position. – sandrstar Nov 06 '12 at 13:52
  • I don't understand the difference between the two cases if/else. You do exactly the same except the color is not set in the first case. That may be the cause of your issue... – sdabet Nov 06 '12 at 13:55
  • I want to differentiate read & unread message from read_id & In my Layout layout_height is not taking fill_parent not wrap_content & it takes 0dp & convert view repeat after every 5 position so when position will 0 again my condition not differentiate messages – Deepanker Chaudhary Nov 06 '12 at 13:59
  • my coler seems after every five row not according to read & unread – Deepanker Chaudhary Nov 06 '12 at 14:00
  • hey @DeepankerChaudhary how did you solve this issue, I am getting the same one, please do tag me :) – Rakeeb Rajbhandari Jan 22 '14 at 11:05
  • @user2247689: Adapter getView() repeat every scroll according to screen side . So if you are facing such type of problem then which logic you put up in adapter it should be use out of adapter means put your data in arraylist outside the adapter with the condition & simply paas arrray list in adapter . – Deepanker Chaudhary Jan 27 '14 at 12:48

1 Answers1

0

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.

sdabet
  • 18,360
  • 11
  • 89
  • 158
  • now i am using this if else condition when m putting the value in arrayList – Deepanker Chaudhary Nov 06 '12 at 14:30
  • @fiddler Can you please answer this question ,I have same problem ,I tried to solve, but no luck . Here is the link : http://stackoverflow.com/questions/33417128/getview-position-is-repeating-in-baseadapter-android – Shishupal Shakya Oct 30 '15 at 10:24