同様の質問がありますが、どれも私の問題を解決しません。
電子メール メッセージが入力されたリストビューがあります。私がやりたいことは、メールが読まれていないときに別のテキストの色とフォントを表示することです. したがって、関連するコードは基本的に次のようになります。
int color = isUnread ? R.color.color_email_unread : R.color.color_email_read;
viewHolder.subject.setTextColor(color);
if (isUnread){
Typeface font = FontFactory.getInstance().getFont(context, "MyFont");
viewHolder.subject.setTypeface(font);
}
しかし、ここでの問題は、特定のテキストビューを変更しないことです。最初のメールが未読で残りが既読であるとします。リストビュー内のすべての項目を color_email_read フォントの色にし、フォントを変更しません。
私が望むようにそれを管理する方法はありますか?その理由は、Android がビューを再利用しないことに関連していますが、解決策を見つけられませんでした。
更新: 常に期待値を返すため、 isUnread が返すものとは関係ありません。
01-30 16:47:42.837: D/EmailListAdapter(5837): isUnread: false
01-30 16:47:42.837: D/EmailListAdapter(5837): isUnread - subject: linktest3 - text color should be: 2131427330
0
01-30 16:47:42.872: D/EmailListAdapter(5837): isUnread: false
01-30 16:47:42.872: D/EmailListAdapter(5837): isUnread - subject: subjectttttttttt - text color should be: 2131427330
01-30 16:47:42.922: D/EmailListAdapter(5837): isUnread: false
01-30 16:47:42.922: D/EmailListAdapter(5837): isUnread - subject: unread test - text color should be: 2131427330
01-30 16:47:42.972: D/EmailListAdapter(5837): isUnread: true
01-30 16:47:42.972: D/EmailListAdapter(5837): isUnread - subject: from unread test - text color should be: 2131427340