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;
}
Aggregations