我写了一个 ArrayAdapter 用于我的 ListActivity 但出于某种原因,当我向下滚动然后向上滚动时,我的列表的顺序正在重新排列,我不知道为什么。加载项目时项目的初始顺序是正确的。问题是当我向下滚动并从屏幕上获取一些最重要的项目然后向上滚动到它们时,它们是不同的。我的 ArrayList 没有从外部来源更改。有人能看到我哪里出错了吗?
public class List3ItemAdapter extends ArrayAdapter {
private final static String DBG = "List3ItemAdapter";
private Activity activity;
private ArrayList<GenericListItem> listItems;
private static LayoutInflater inflater;
private ArrayList<View> listViews;
public List3ItemAdapter(Activity activity, ArrayList<GenericListItem> listItems) {
super(activity, android.R.layout.simple_list_item_1);
this.listItems = listItems;
this.activity = activity;
this.listViews = new ArrayList<View>();
inflater = (LayoutInflater) activity.getSystemService(activity.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return listItems.size();
}
public Object getItem(int position) {
return listItems.get(position);
}
public long getItemId(int position) {
return position;
}
public View getViewByPos(int pos) {
return listViews.get(pos);
}
public View getView(int position, View convertView, ViewGroup parent) {
// Log.d(DBG, "current position is: " + position);
View vi = convertView;
GenericListItem listItem = listItems.get(position);
ArrayList<String> values = listItem.getDisplayValues();
if (vi == null) {
if (listItem.getIsSection()) {
vi = inflater.inflate(R.layout.list_section, null);
} else {
vi = inflater.inflate(R.layout.list_3itemrow, null);
}
listViews.add(vi);
}
if (listItem.getIsSection()) {
TextView sectionTitle = (TextView) vi.findViewById(R.id.sectionTitle);
sectionTitle.setText(values.get(0));
} else {
TextView title = (TextView) vi.findViewById(R.id.primaryTitle);
TextView secondary = (TextView) vi.findViewById(R.id.secondaryTitle);
TextView rightData = (TextView) vi.findViewById(R.id.rightData);
secondary.setVisibility(View.GONE);
rightData.setVisibility(View.GONE);
Integer count = 0;
for (String str : values) {
count++;
if (count == 1) {
title.setText(str);
} else if (count == 2) {
secondary.setText(str);
secondary.setVisibility(View.VISIBLE);
} else if (count == 3) {
rightData.setText(str);
rightData.setVisibility(View.VISIBLE);
}
}
}
return vi;
}
}