I have a problem with the Android UI that I can't seem to solve.
My main activity (a ListActivity
) displays a list of items. When the user clicks one, it causes the underlying data to be updated (queried from a web service) through an AsyncTask
. When the request terminates successfully, I call notifyDataSetChanged()
to have the new information displayed.
It is my understanding that the getView
method from my custom BaseAdapter
will be called to perform the rendering :
private List<InstalledApp> data;
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null) {
convertView = LayoutInflater.from(ctx).inflate(R.layout.list_item, parent, false);
}
InstalledApp app = data.get(position);
String latest_version = app.getLatestVersion();
TextView version = (TextView) convertView.findViewById(R.id.version);
if (latest_version != null)
{
if (app.getVersion().equals(latest_version))
{
version.setText(app.getVersion());
version.setTextColor(Color.GREEN);
}
else
{
version.setText(app.getVersion() + " (Current: " + latest_version + ")");
version.setTextColor(Color.RED);
}
}
else {
version.setText(app.getVersion());
}
return convertView;
}
The problem is that when an item is updated and this gets called, two items have their colors changed. But the textual content remain correct. The second one is usually not visible immediately, and I have to scroll down the list to see it. Do you have any idea what could be causing this?