以下是修正后的代码:

public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;

    if (view == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        view = inflater.inflate(R.layout.calendar_item, parent, false);
    }

    TextView tvDate = view.findViewById(R.id.tv_date);
    Date date = dates.get(position);
    tvDate.setText(dateFormat.format(date));

    if (date.getMonth() != currentDate.getTime().getMonth()) {
        tvDate.setTextColor(Color.GRAY);
    } else {
        tvDate.setTextColor(Color.BLACK);
    }

    if (markedDates.contains(date)) {
        tvDate.setBackgroundResource(R.drawable.circle_background); // 设置已打卡日期的背景样式
    } else {
        tvDate.setBackground(null); // 清除未打卡日期的背景样式
    }

    return view;
}

非常抱歉给你带来了困扰。以上是修正后的getView()方法的代码。感谢你的耐心和理解。

Android ListView getView() 方法实现日历视图:优化代码示例

原文地址: https://www.cveoy.top/t/topic/beZA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录