我在 android 应用程序中有一些用于 gridview 的自定义适配器。当我第一次启动应用程序时一切正常,但是当我单击按钮并调用函数 refreshCalendar() 时,适配器“记住”文本属性(字体:BOLD)。我检查(列表)calendarCells 并且没有错误。
public class FCalCellsAdapter extends BaseAdapter{
private static final String TAG = "FCalCellsAdapter";
private Context context;
private LayoutInflater inflater;
private List<FCalCell> calendarCells;
public FCalCellsAdapter(Context context, List<FCalCell> calendarCells){
this.context = context;
this.calendarCells = calendarCells;
this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void refreshCalendarCells(List<FCalCell> calendarCells){
this.calendarCells = calendarCells;
}
@Override
public int getCount() {
return calendarCells.size();
}
@Override
public Object getItem(int position) {
return calendarCells.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Holder holder;
View v = convertView;
if(convertView == null){
holder = new Holder();
v = inflater.inflate(R.layout.gridview_item_cell, null);
holder.cellBackground = (ImageView) v.findViewById(R.id.cell_background);
holder.cellDay = (TextView) v.findViewById(R.id.cell_day);
holder.cellPeriodDay = (TextView) v.findViewById(R.id.cell_period_day);
v.setTag(holder);
}else{
holder = (Holder) v.getTag();
}
if(calendarCells.get(position).getDayType() == FCalCell.DAY_TYPE_ACTIVE_MONTH){
holder.cellBackground.setBackgroundResource(R.drawable.background_cell_white);
}else if(calendarCells.get(position).getDayType() == FCalCell.DAY_TYPE_TODAY){
holder.cellBackground.setBackgroundResource(R.drawable.background_cell_today);
holder.cellDay.setTypeface(Typeface.DEFAULT_BOLD);
}else{
holder.cellBackground.setBackgroundResource(R.drawable.background_cell_gray);
}
holder.cellDay.setText(calendarCells.get(position).getNumberOfDay());
holder.cellPeriodDay.setText(String.valueOf(calendarCells.get(position).getPeriodDayNumber()));
return v;
}
private class Holder{
private ImageView cellBackground;
private TextView cellDay;
private TextView cellPeriodDay;
}
}
refreshCalendar(主要活动)
public void refreshCalendar(){
List<FCalCell> calendarCells = FCal.getListOfCalendarCells(actualMonth,this);
adapter.refreshCalendarCells(calendarCells);
adapter.notifyDataSetChanged();
}