Calendar on Android

0

Hello everyone, I'm new here and forgive me for some immaturity in the programming area for Android. I have a java application that needs to get a date, so my idea is a button where it opens a calendar (current) and the person can choose a day like jcalendar from java, I do not know if You can understand my question, but I'm waiting for the answers .... Thanks in advance for everything ...

    
asked by anonymous 21.03.2017 / 13:06

2 answers

0

I developed a similar canvas once. The layout may be what you imagine. follows the methods I did to call the android calendar and capture the date selected by the user in an edit.

edt_data = (EditText)findViewById(R.id.edt_data);
bCalendario= (Button)findViewById(R.id.b_calendario);
bCalendario.setOnClickListener(new View.OnClickListener()   {
  @SuppressWarnings("deprecation")
  public void onClick(View v)  {
    showDialog(DATE_DIALOG_ID); //chamar o calendario
  }
});

@Override
protected Dialog onCreateDialog(int id) {
  switch (id) {
    case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener,mYear, mMonth-1, mDay);
  }
  return null;
}

private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
  public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    mYear = year;
    mMonth = monthOfYear;
    mDay = dayOfMonth;
    updateDisplay();
  }
};

private void updateDisplay() {
        edt_data.setText(new StringBuilder()
                // Month is 0 based so add 1
                .append(mDay).append("/")
                .append(mMonth + 1).append("/")
                .append(mYear).append(" "));
    }
    
21.03.2017 / 13:19
-1

I do not know if that's what you need, but I also had to work with the calendar and I found this library very good:

link

final CollapsibleCalendar collapsibleCalendar = findViewById(R.id.calendarView);

collapsibleCalendar.setCalendarListener(new CollapsibleCalendar.CalendarListener() {

    @Override
    public void onDaySelect() {
        Day day = viewCalendar.getSelectedDay();
        Log.i(getClass().getName(), "Selected Day: "
                + day.getYear() + "/" + (day.getMonth() + 1) + "/" + day.getDay());
    }

    @Override
    public void onItemClick(View view) {

    }

    @Override
    public void onDataUpdate() {

    }

    @Override
    public void onMonthChange() {

    }

    @Override
    public void onWeekChange(int i) {

    }
});
    
04.06.2018 / 02:40