我已经创建了一个自定义的ArrayAdapter来显示数据结构数组中的ListView项目中的数据,并且出于某种原因,当我快速上下滚动时,显示会做出奇怪的事情。ListView项目不能正确刷新
这是我的自定义ArrayAdapter的getView函数。我的第一个猜测是因为if(d.highTemp!= null)导致滞后或什么?如果数据结构中有一个值,我想让适配器执行的操作只是显示一个highTemp。否则,它应该显示lowTemp值;这份名单是正确的,当最初绘制的,但如果我向上和向下滚动真快,它会开始显示高和lowTemp值,即使我知道每个数据结构只有其中的一个!= NULL ...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_item, null);
}
DaysWeather d = daysWeather[position];
if (d != null) {
TextView tt = (TextView) v.findViewById(R.id.toptext);
TextView bt = (TextView) v.findViewById(R.id.bottomtext);
TextView trt = (TextView) v.findViewById(R.id.toprighttext);
TextView tbt = (TextView) v.findViewById(R.id.bottomrighttext);
if (tt != null) {
tt.setText(d.name);}
if(bt != null){
bt.setText(d.shortDescription);
}
if (d.highTemp != null){
if (trt != null) {
trt.setText("Hi: " + d.highTemp);
tbt = null;
}
} else {
if (tbt != null) {
trt = null;
tbt.setText("Lo: " + d.lowTemp);
}
}
}
return v;
}
这样做!我已经尝试过'tbt = null'和'trt = null',但它不能正常工作,但是使用了空setText!!非常感谢。 – joepetrakovich 2010-11-11 01:59:54