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

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

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

           holder = newHolder();
            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.

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
    Holderholder=newHolder();
    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

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
Holderholder=newHolder();
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"