I have an activity with a ListView which is populated through a custom ArrayAdapter. There is an array of objects which have a Boolean property called 'isRead'. Based on the value of this property, I want to set the typeface of one of the TextViews in the row to either 'normal' or 'bold'. I also set the color of the text to either 'gray' or 'black'
When the Activity initially starts up, everything works as expected. If isRead is true, the text is gray with a normal font. Once I scroll down the list and then scroll up again, the text of an object where isRead is true is colored gray, but the font is bold.
Am I doing something wrong here? Or is this some Android strangeness?
ArrayAdapter code is below:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = convertView;
ArticleListRowViewWrapper wrapper=null;
if (row == null) {
row=inflater.inflate(R.layout.articlesrow, parent, false);
wrapper = new ArticleListRowViewWrapper(row);
row.setTag(wrapper);
} else {
wrapper = (ArticleListRowViewWrapper)row.getTag();
}
Article a = articles.get(position);
String dateString = df.format(a.getPubDate());
TextView titleLabel=wrapper.getTitleLabel();
Typeface tf = titleLabel.getTypeface();
if (a.getIsRead()) {
titleLabel.setTextColor(Color.GRAY);
titleLabel.setTypeface(tf, Typeface.NORMAL);
} else {
titleLabel.setTextColor(Color.BLACK);
titleLabel.setTypeface(tf, Typeface.BOLD);
}
titleLabel.setText(a.getTitle());
TextView dateLabel =wrapper.getDateLabel();
dateLabel.setText(dateString);
return row;
}
}