Android日历示例

时间:2017-08-04 00:44:04

标签: android android-fragments calendar

我正在尝试在我的应用中使用素材日历视图库https://github.com/prolificinteractive/material-calendarview。 问题是我需要在片段中创建日历视图,并在日期点击我需要创建与所选日期相关的另一个片段。任何人都可以为此做一个例子吗?

1 个答案:

答案 0 :(得分:0)

它显示日历,但点击监听器不起作用

public class CalendarFragment extends Fragment {

    private MaterialCalendarView calendarView;

    public CalendarFragment() {
        FragmentsUtils.addFragment(this, "Calendar", "Calendario ricordi", 
            null, R.id.content_main_layout);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_calendar, container, 
            false);

        calendarView = (MaterialCalendarView) 
            view.findViewById(R.id.calendarView);

        calendarView.setOnDateChangedListener(new OnDateSelectedListener() {

            @Override
             public void onDateSelected(@NonNull MaterialCalendarView 
                 widget, @NonNull CalendarDay date, boolean selected) {

             Log.e("DAY", "DAY:" + date);
            }
        });

    return calendarView;
}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

}