traex / CalendarListview

Implementation of a calendar in a ListView. One month by row
MIT License
1.48k stars 438 forks source link

CalendarListView in Fragment #44

Open thanhhaiqtvn opened 8 years ago

thanhhaiqtvn commented 8 years ago

Hello,

how to add this calendar to Fragment. Can you show me. thank u.

ozcanyarimdunya commented 8 years ago

CALENDAR_FRAGMENT.JAVA

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.andexert.calendarlistview.library.DatePickerController;
import com.andexert.calendarlistview.library.DayPickerView;
import com.andexert.calendarlistview.library.SimpleMonthAdapter;
import com.yourpackagename.R; //***//

import java.util.Calendar;

public class CalendarFragment extends Fragment implements DatePickerController {

    private DayPickerView dayPickerView;

    public CalendarFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View view = inflater.inflate(R.layout.fragment_calendar, container, false);
        dayPickerView = (DayPickerView) view.findViewById(R.id.pickerView);
        dayPickerView.setController(this);

        return view;
    }

    @Override
    public int getMaxYear() {
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        return year + 1;
    }

    @Override
    public void onDayOfMonthSelected(int year, int month, int day) {

    }

    @Override
    public void onDateRangeSelected(SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> selectedDays) {

    }
}

FRAGMENT_CALENDAR.XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:calendar="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CalendarFragment">

    <com.andexert.calendarlistview.library.DayPickerView
        android:id="@+id/pickerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        calendar:colorCurrentDay="#ff0000"
        calendar:colorSelectedDayBackground="#000000"
        calendar:currentDaySelected="true"
        calendar:drawRoundRect="false"/>

</RelativeLayout>