I'm having a problem with a ListActivity. I've extended ArrayAdapter and Overridden getView to fill in the data for each row. I throw some data from my Adapter's ArrayList into a TextView.
My problem is, when I scroll, the TextView of each row populates with text that is not in its corresponding data in the ArrayList. What I mean is: say I have a row at the top of my list with a TextView that is populated with emptystring. If I'm at the bottom of my list and see a row with a TextView populated with "bob" and I flick to scroll to the top, the row at the top may now have "bob" in its TextView, but the data at that index of my ArrayList does not contain "bob." It contains emptystring (actually null). If I continue scrolling up and down, other rows will populate (or erase) with data that doesn't correspond to what's in the Adapter's ArrayList.
To cause this to happen, I don't need to scroll the ListView fast. However, it appears the faster I scroll, the more rows get messed up.
Here is my code. I realize I'm using findViewById every time getView gets called, but that's beside the point. I'm calling it against convertView; so it should be grabbing the correct TextView on each row, yes?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// get the View for this list item
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.layout_mylistlist_item, null);
}
// get the next object
MyListItem myItem = m_items.get(position);
// set up the list item
if (myItem != null) {
TextView txtName = (TextView) v.findViewById(R.id.mylist_name);
// set text
if (txtName != null && myItem.getName() != null) {
txtName.setText(myItem.getName());
}
}
// return the created view
return v;
}