I wrote a an ArrayAdapter to be used in my ListActivity but for some reason when i scroll down and then scroll back up the order of my list is being rearranged and i have no idea why. The initial order of the items when the items are loaded is correct. The problem is when i scroll down and get a few of the top items off the screen and then scroll back up to them, they're different. My ArrayList isn't being changed from an outside source. Can someone see where i'm going wrong?
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;
}
}