我已經創建了一個自定義的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