使用MaterialCalendarView

时间:2017-11-13 04:39:13

标签: java android calendarview

我尝试了很多,操纵那件事。我想每次点击一些日历时添加popup-window

public class TabAgendaFragment extends Fragment {
    private static final String TAG = "Agenda";

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.tab_agenda_fragment, container, false);

        MaterialCalendarView materialCalendarView = (MaterialCalendarView) view.findViewById(R.id.calendarView);
        materialCalendarView.setOnDateChangedListener(new OnDateSelectedListener() {
            @Override
            public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
                //Toast.makeText(getActivity(), "" + date, Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }
}

我如何做到这一点,我尝试在popup内部创建一个OnDateSelectedListener窗口,但没有成功。有人可以帮帮我吗?谢谢:))

1 个答案:

答案 0 :(得分:0)

您可以在onDateSelected方法上创建poup-window而不会出现任何问题,可能在您的情况下没有创建活动,因此您应该在创建活动后编写代码。

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    MaterialCalendarView materialCalendarView = (MaterialCalendarView) getView().findViewById(R.id.calendarView);
    materialCalendarView.setOnDateChangedListener(new OnDateSelectedListener() {
        @Override
        public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage("My Message").setTitle("Title");
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    });
}