I am trying to build a RSS feed reader for my application and I have a weird problem. To implement this feed I use a ListView that I populate from an ArrayList I customised.
I know that the ArrayList is full with all the fields I want to display (I print all of them in my Logcat), but when I run the app, not all the cells in my ListView fill with the information they are supposed to, the major part of them display TextView. It seems to be quite random, but the one that always works correctly is the first element. The other ones some times do.
And another strange thing is that the OnItemClickListener works perfectly, even I am unable to see the information in my elements.
Thank you very much in advanced.
I attach my getView code:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
AdapterWrapper wrapper;
if (v == null) {
LayoutInflater li = (LayoutInflater) this.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.itemrow, null);
wrapper = new AdapterWrapper(v, cont);
v.setTag(wrapper);
} else {
wrapper = (AdapterWrapper) convertView.getTag();
RssItem o = this.getItem(position);
if (o != null)
wrapper.populateFrom(o);
parent.refreshDrawableState();
}
return v;
}
Probably you aren’t handling the recycled view case properly in
getView.When you check to see that
convertView != null, you still need to actually populate the information in your convertView. The actual view hierarchy will be there, but the information will be from an old, recycled view associated with a different row.For more specific information, please post your
getViewcode.Edit – I think you need to call
wrapper.populateFrom(o)whether or not you have aconvertView. Try moving that part outside of the if statement: