Search in sources :

Example 1 with CalendarView

use of android.widget.CalendarView in project IITB-App by wncc.

the class CalendarFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_calendar, container, false);
    fab = (FloatingActionButton) view.findViewById(R.id.fab);
    // get the reference of CalendarView
    final CalendarView simpleCalendarView = (CalendarView) view.findViewById(R.id.simpleCalendarView);
    // set Sunday as the first day of the week
    simpleCalendarView.setFirstDayOfWeek(1);
    // setWeekNumberColor
    simpleCalendarView.setWeekNumberColor(getResources().getColor(R.color.colorCalendarWeek));
    simpleCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {

        @Override
        public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
            if (toast != null) {
                toast.cancel();
            }
            toast = Toast.makeText(getContext(), "Date: (" + dayOfMonth + "/" + (month + 1) + "/" + year + ")", Toast.LENGTH_LONG);
            toast.show();
        }
    });
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AddEventFragment addEventFragment = new AddEventFragment();
            addEventFragment.setArguments(getArguments());
            FragmentTransaction ft = getChildFragmentManager().beginTransaction();
            ft.replace(R.id.calendar_layout, addEventFragment);
            ft.addToBackStack("addEvent");
            ft.commit();
        }
    });
    return view;
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) CalendarView(android.widget.CalendarView) CalendarView(android.widget.CalendarView) View(android.view.View)

Aggregations

FragmentTransaction (android.support.v4.app.FragmentTransaction)1 View (android.view.View)1 CalendarView (android.widget.CalendarView)1