Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Change Year directly in material-calendarview

I am using https://github.com/prolificinteractive/material-calendarview

Right now it is changing the month on the click of Right or Left arrow
How can i change the year directly instead of changing month.
Is this possible android default Calendar View. Below is my code for prolificinteractive - calendar

public class ActivityCalendar extends AppCompatActivity implements OnDateSelectedListener, OnMonthChangedListener {

    private static final DateFormat FORMATTER = SimpleDateFormat.getDateInstance();
    private MaterialCalendarView widget;
    private String zodiacSign = "";
    private HashMap<String,Integer> hashMapMonth =  new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_calendar);
        widget = (MaterialCalendarView)findViewById(R.id.calendarView);
        widget.setOnDateChangedListener(this);
        widget.setOnMonthChangedListener(this);

    }

    @Override
    public void onDateSelected(@NonNull MaterialCalendarView widget, @Nullable CalendarDay date, boolean selected) {
        String strDate = getSelectedDatesString();
        Intent returnIntent = new Intent();
        returnIntent.putExtra(TagClass.BIRTH_DATE, strDate);
        setResult(Activity.RESULT_OK, returnIntent);
        finish();
    }


    @Override
    public void onMonthChanged(MaterialCalendarView widget, CalendarDay date) {
        //noinspection ConstantConditions

    }

    private String getSelectedDatesString() {
        CalendarDay date = widget.getSelectedDate();
        if (date == null) {
            return "No Selection";
        }
        return FORMATTER.format(date.getDate());
    }
}

Layout.XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ActivityCalendar">


    <com.prolificinteractive.materialcalendarview.MaterialCalendarView
        android:id="@+id/calendarView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />


</LinearLayout>
like image 302
ojas Avatar asked Dec 31 '15 14:12

ojas


1 Answers

That doesn't seem to be possible with that library as it is right now.

In order order to do it, you would need to download the sources from github, and add it to your project as a library module.

Then, I would expect changes to be needed in at least these components:

  • MaterialCalendarView.java, to change the naming or usage of the Adapter in the ViewPager.OnPageChangeListener
  • CalendarPagerAdapter.java, to provide year items instead of months.

Also, my impression is that doing these changes would also cause a mayor refactor in the library.

like image 122
FlyingPumba Avatar answered Oct 21 '22 06:10

FlyingPumba