ListView视图更改滚动位置

时间:2014-01-12 17:59:00

标签: android listview scroll position

我有一个简单的listview用自定义视图充气,点击时会改变颜色。问题是当我滚动列表时,项目的位置随机变化。这是我的适配器代码。在我的getview方法中有什么明显的东西我不见了吗?感谢您的帮助。

public class HADevicesAdapter extends ArrayAdapter<HADevicesViews>{
private static final String HADevicesViews = null;
private final String TAG = HADevicesAdapter.class.getSimpleName();
private Context context;    
private ArrayList<HADevicesViews> arrayList;
 OnClickListener listner;
 LayoutInflater inflater;
public HADevicesAdapter(Context context, ArrayList<HADevicesViews> arrayList,             OnClickListener listner) {
    // TODO Auto-generated constructor stub
    super(context, R.layout.layout_endpoints_list_row,arrayList);
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.context = context;
    this.listner = listner;
    this.arrayList = arrayList;
}

@Override
public int getViewTypeCount() {
    // TODO Auto-generated method stub
    return 1;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return arrayList.size();
}

@Override
public HADevicesViews getItem(int position) {
    // TODO Auto-generated method stub
    return arrayList.get(position);
}

@Override
public int getPosition(HADevicesViews item) {
    // TODO Auto-generated method stub
    return arrayList.indexOf(item);
}

@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if(convertView == null){            
        convertView = inflater.inflate(R.layout.layout_endpoints_list_row, parent,false);       
        viewHolder = new ViewHolder();
        viewHolder.haDeviceView = (HADevicesViews) convertView.findViewById(R.id.onOffOutput);          
        convertView.setTag(viewHolder);                     
    }else{
        viewHolder = (ViewHolder) convertView.getTag();
    }

    viewHolder.haDeviceView.setOnClickListener(listner);

    return convertView;
 }

 static class ViewHolder{ 
    HADevicesViews haDeviceView;        
}

}

0 个答案:

没有答案