I have two ListView
s lets call them 1 and 2. I add items to ListView 1
and then after a certain amount of time, I move the item to ListView 2
.
The problem I'm having is that sometimes (I haven't worked out the pattern yet) the text shown in ListView 1
is wrong - it shows the previously created item's text. But when I move it to ListView 2
it shows the correct text.
I understand views are recycled so the list item could be using the old view. I don't think it is doing this as it shows the correct info in the other list.
It could be that it is taking too long to set the text as there is a lot of it in the getView()
method, so it uses the old values while it updates in the background. I don't know if this is possible, but even when I call notifyDataSetChanged()
the wrong info is still being shown.
Here is my code:
ListView 1
.
This is the adapter for the List:
public class PendingAdapter extends BaseAdapter {
private List<Map<String, Object>> mPendingItemList;
public PendingAdapter() {
mPendingItemList = DataModel.getInstance().getPendingItemList();
}
@Override
public int getCount() {
return mPendingItemList.size();
}
@Override
public Object getItem(int position) {
return mPendingItemList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = LayoutInflater.from(getActivity()).inflate(
R.layout.pending_item, null);
}
TextView tv_title = (TextView) convertView
.findViewById(R.id.pi_tv_title);
TextView tv_content = (TextView) convertView
.findViewById(R.id.pi_tv_content);
TextView tv_counter = (TextView) convertView
.findViewById(R.id.pi_tv_counter);
TextView tv_ongoing = (TextView) convertView
.findViewById(R.id.pi_tv_ongoing);
TextView tv_type = (TextView) convertView
.findViewById(R.id.pi_tv_type);
TextView tv_date = (TextView) convertView
.findViewById(R.id.pi_tv_date);
@SuppressWarnings("unchecked")
HashMap<String, String> itemDataHashMap = (HashMap<String, String>) getItem(position);
tv_title.setText(itemDataHashMap.get("planet"));
tv_content.setText(itemDataHashMap.get("content"));
tv_counter.setText(itemDataHashMap.get("counter"));
tv_type.setText(itemDataHashMap.get("type"));
tv_ongoing.setText(itemDataHashMap.get("ongoing"));
tv_date.setText(itemDataHashMap.get("date"));
return convertView;
}
}
I am not sure which other pieces of code would be helpful (maybe the mPendingItemList
) - but if more would help please say :-).