Doubts with timessquare CalendarPickerView

3

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

I've found in some places that the init () method can disable the day but I could not get it to just take 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);
}
    
asked by anonymous 09.06.2016 / 14:29

1 answer

2

Good morning, Shara!

I've never used CalendarPickerView but always the DateTimePicker from Android itself. Unfortunately the DateTimePicker is not a very flexible component as you need, for example, painting the days of the week that the user could not choose in red.

However, to offer an alternative, you could use the DatePickerDialog itself to handle the return event of the date assignment:

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 if the day of the week is accepted. If not, kindly inform the user by means of 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 have helped,

    
09.06.2016 / 15:03