我有一个ListView
在create上正确填充了一个数组,但是当我滚动时,数据会发生变化并且全部乱序。我不知道问题出在我的CustomListViewAdapter
或我的详情页面中。这是我用来生成For Loop
的{{1}}:
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));
的代码:
customListViewAdapter
答案 0 :(得分:2)
您可以使用这些代码行替换代码
@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;
}
答案 1 :(得分:1)
使用下面的 getView()。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder = new Holder();
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;
}
答案 2 :(得分:1)
你可能没有实现设计持有人。对你的getView进行以下更改,然后它将正常工作
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder = new Holder();
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;
}