I am working with a list view with customer ArrayAdapter. I have overridden getView to update the text views in a TableLayout. After updating the text a gradient is applied to a group of table rows to dynamically highlight the relevant information at any given time. Unfortunately this highlighting does not always appear as I would expect. The expected appearance is as follows:
However, immediately at startup and then if I click on a list item the appearance changes:
and there is space visible between gradient applied to each table row. My theory is that the row height is changing when the text is modified, but the gradient size is being calculated prior to the redraw. Then when the rows are redrawn with the same text they appear correct (since the row height didn't change).
I'm looking for any suggestion to resolve this issue, preferably a setting make the table behave the way I want or an API call that will for the size of the rows to be recalculated prior to applying the gradient. Alternatively a better technique that will produce more reliable behavior.
I have already tried invalidating the whole table and the individual rows prior to applying the gradient. This had no effect.
The code that draws the gradient follows:
TableRow travelInfoRow = (TableRow) v.findViewById(R.id.travelInfo);
TableRow arrivalInfoRow = (TableRow) v.findViewById(R.id.arrivalInfo);
TableRow destinationInfoRow = (TableRow) v.findViewById(R.id.destinationInfo);
TableRow departureInfoRow = (TableRow) v.findViewById(R.id.departureInfo);
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, new int[] { 0xff0b4496, 0xff000000 });
if (item.enRoute()) {
travelInfoRow.setBackgroundDrawable(gd);
} else {
travelInfoRow.setBackgroundColor(Color.BLACK);
}
if (item.atLocation()) {
arrivalInfoRow.setBackgroundDrawable(gd);
destinationInfoRow.setBackgroundDrawable(gd);
departureInfoRow.setBackgroundDrawable(gd);
} else {
arrivalInfoRow.setBackgroundColor(Color.BLACK);
destinationInfoRow.setBackgroundColor(Color.BLACK);
departureInfoRow.setBackgroundColor(Color.BLACK);
}