Skip to content Skip to sidebar Skip to footer

ListView Changes Data On Scroll

I have a ListView that is correctly populated with an array on create, but when I scroll, the data changes and is all out of order. I don't know wether the problem is in my CustomL

Solution 1:

You replace the code with these lines of code

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

    final Holder holder;
    View v = convertView;
    if (v == null)
        {

           holder = new Holder();
            v = inflater.inflate(R.layout.busdetailrow, null);

            holder.tv1 = (TextView) v.findViewById(R.id.text);
            holder.tv2 = (TextView) v.findViewById(R.id.text2);

        v.setTag(holder);
        } else {

           holder = (Holder) v.getTag();
        }

            holder.tv1.setText(locations[position]);
            holder.tv2.setText(times[position]);

    return v;
 }

Solution 2:

Use your getView() like below.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Holder holder = new Holder();
    if (convertView == null){
        if (locations[position] != null && times[position] != null) {
            convertView = inflater.inflate(R.layout.busdetailrow, null);
            holder.tv1 = (TextView) v.findViewById(R.id.text);
            holder.tv2 = (TextView) v.findViewById(R.id.text2);
            holder.tv1.setText(locations[position]);
            holder.tv2.setText(times[position]);
        } else {

        }
        convertView.setTag(holder);
    }else{
        holder = (Holder) convertView.getTag();
    }
    return convertView;
}

Solution 3:

You didnt implement design holder probably. make following changes to your getView then it will work fine

  @Override
 public View getView(int position, View convertView, ViewGroup parent) {
Holder holder = new Holder();
if (convertView == null){

    if (locations[position] != null && times[position] != null) {
        convertView = inflater.inflate(R.layout.busdetailrow, null);
        holder.tv1 = (TextView) v.findViewById(R.id.text);
        holder.tv2 = (TextView) v.findViewById(R.id.text2);
        holder.tv1.setText(locations[position]);
        holder.tv2.setText(times[position]);

    } 
      else 
    {

    }
    convertView.setTag(holder);
}else{
    holder = (Holder) convertView.getTag();
}
return convertView;
}

Post a Comment for "ListView Changes Data On Scroll"