ListView更改滚动数据

ListView更改滚动数据

本文介绍了ListView更改滚动数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView ,它正确地用create创建了一个数组,但是当我滚动的时候,数据改变了,而且都是乱序的。我不知道问题出在我的 CustomListViewAdapter 或我的DetailsPage中。下面是我用来生成 textViews 的 For循环:

  if(currentObject.setTime!= null&&& currentObject.setName!= null){
String [] temporaryNames = currentObject.setName;
int totalNames =(currentObject.setTime.length / currentObject.setName.length); (int i = 1; i currentObject.setName = ArrayUtils.addAll(currentObject.setName,temporaryNames);





listView.setAdapter(new,BusRouteCustomListViewAdapter(this,currentObject.setName,currentObject.setTime));

这里是我的 customListViewAdapter :
$ b $ pre $ @Override
public View getView(int position,View convertView,ViewGroup parent){

持有人持有人=新持有人();
查看v = convertView;
if(v == null)
if(locations [position]!= null&& times [position]!= null){
v = 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 {

v = inflater.inflate(R.layout.null_row,null);
}

return v;


解决方案

代码行

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

最终持有人;
查看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(持有人);
} else {

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

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

return v;
}


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 CustomListViewAdapter or in my DetailsPage. Here's the For Loop that I am using to generate the textViews:

if (currentObject.setTime != null && currentObject.setName != null) {
            String[] temporaryNames = currentObject.setName;
            int totalNames = (currentObject.setTime.length / currentObject.setName.length);

            for (int i = 1; i < totalNames; i++) {
                currentObject.setName = ArrayUtils.addAll(currentObject.setName,temporaryNames);
            }
        }

    listView.setAdapter(new BusRouteCustomListViewAdapter(this, currentObject.setName, currentObject.setTime));

and here is the code for my customListViewAdapter:

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

    Holder holder = new Holder();
    View v = convertView;
    if (v == null)
        if (locations[position] != null && times[position] != null) {
            v = 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 {

            v = inflater.inflate(R.layout.null_row, null);
        }

    return v;
}
解决方案

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;
 }

这篇关于ListView更改滚动数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 04:28