如何在android中的日历上的特定日期设置点

时间:2018-01-23 07:20:40

标签: java android import kotlin

这是点击日期的代码显示事件,但在事件日期我看不到DOT,我试图做但事情没有发生。

package com.example.mis_internee.mycalentest;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.github.sundeepk.compactcalendarview.CompactCalendarView;
import com.github.sundeepk.compactcalendarview.domain.Event;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import static android.graphics.Color.RED;

public class MainActivity extends AppCompatActivity {

    CompactCalendarView compactCalendar;
    private SimpleDateFormat dateFormatMonth = new SimpleDateFormat("MMMM- yyyy", Locale.getDefault());

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(null);

        compactCalendar = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
        compactCalendar.setUseThreeLetterAbbreviation(true);
        compactCalendar.setEventIndicatorStyle(Color.BLACK);
        compactCalendar.setCurrentDayBackgroundColor(RED);
        compactCalendar.getEvents(3223213);

        //Set an event for Teachers' Professional Day 2016 which is 21st of October

        Event ev1 = new Event(Color.BLACK, 1477040400000L, "Teachers' Professional Day");
        compactCalendar.addEvent(ev1);

        compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
            @Override
            public void onDayClick(Date dateClicked) {
                Context context = getApplicationContext();

                if (dateClicked.toString().compareTo("Fri Jan 26 00:00:00 GMT+05:00 2018") == 0) {
                    Toast.makeText(context, "Teachers' Professional Day", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(context, "No Events Planned for that day", Toast.LENGTH_SHORT).show();
                }


            }

            @Override
            public void onMonthScroll(Date firstDayOfNewMonth) {
                actionBar.setTitle(dateFormatMonth.format(firstDayOfNewMonth));
            }
        });
    }
}

提前致谢

1 个答案:

答案 0 :(得分:1)

您正在此处设置时间戳1477040400000L

Event ev1 = new Event(Color.BLACK, 1477040400000L, "Teachers' Professional Day");
        compactCalendar.addEvent(ev1);

时间戳1477040400000LFriday, 21 October 2016 09:00:00 GMT +5:30 所以检查那个日期

如果您想设置Fri Jan 26 00:00:00 GMT+05:00 2018设置

Event ev1 = new Event(Color.BLACK,1516924800000L, "Teachers' Professional Day");
        compactCalendar.addEvent(ev1);

enter image description here