Doubts with timessquare Calendarpickerview

Asked

Viewed 44 times

3

How to disable the day of the week example:I have calendar, I spent the day of the week by parameter in the case Monday, Thursday and Sunday to schedule service. How do I disable Tuesday, Wednesday and Friday using timessquare Calendarpickerview?

I’ve looked in some places where the init() method can disable the day but I couldn’t get it to take only the day of the week.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="webservice.tablayout.teste"
android:id="@+id/layout">

public class AgendarActivity extends AppCompatActivity implements View.OnClickListener {

private Servico servico;

private SimpleDateFormat sdFormat;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_agendar);

    Calendar nextYear = Calendar.getInstance();
    nextYear.add(Calendar.DAY_OF_WEEK, 1);

    CalendarPickerView calendar = (CalendarPickerView)      findViewById(R.id.calendarPV);
    Date today = new Date();

    calendar.init(today, nextYear.getTime()).withSelectedDate(today);
}

1 answer

2

Good morning Xará!

I never used Calendarpickerview but always the Datetimepicker of Android itself. Unfortunately the Datetimepicker is not a quite flexible component as you need, for example, painting the days of the week red that the user could not choose.

However, to offer an alternative, you could use the Datepickerdialog itself dealing with the date assignment return event:

DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

        myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        myCalendar.set(Calendar.MONTH, monthOfYear);
        myCalendar.set(Calendar.YEAR, year);

    }
};

In this Listener, you can check whether the day of the week is accepted. If not, kindly inform the user through a Toast or Snackbar, instructing what he should do but not preventing him from clicking on a date, reopening the calendar for example.

I hope I’ve helped,

  • In case I do not need to make these flexibilities to paint, in case I would need the most important result that in question would disable the days of the week, I will perform test with Datetimepicker and I return to give an answer, thanks for the help ;)

  • @Matheus cool! Hopefully you can solve the problem. If you have more questions about, comment! Hug

  • I gave a search I could not find the method that when I click on the calendar calls a method, you can tell me which is ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.