Custom Android calendarView

sankettt picture sankettt · Feb 19, 2014 · Viewed 73.8k times · Source

I am looking for a CalendarView that can be used in a dialog something like this:

I plan to use android.widget.CalendarView but it is available from API level 11. That's an issue considering there are still lot of users, using android 2.3.3 (but not a major one can let go those set of user).

Which of these options should I use?

1) libraries that are available and use them accordingly.

2) customize the android.widget.CalendarView?

If #2, then are there any examples for it?

Answer

Jitesh Upadhyay picture Jitesh Upadhyay · Feb 19, 2014

Hi visit all given links, hope will help you

  1. Betterpickers: https://github.com/derekbrameyer/android-betterpickers

  2. Calendar Sync: http://www.androiddevelopersolutions.com/2013/05/android-calendar-sync.html

  3. Simple Calendar: http://w2davids.wordpress.com/android-simple-calendar/

  4. Caldroid: https://github.com/roomorama/Caldroid

  5. DateTimePicker: https://github.com/flavienlaurent/datetimepicker

When you visit Betterpickers, for a working implementation of this project see the sample/ folder.

Implement the appropriate Handler callbacks:

public class MyActivity extends Activity implements DatePickerDialogFragment.DatePickerDialogHandler {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    // ...
  }

  @Override
  public void onDialogDateSet(int year, int monthOfYear, int dayOfMonth) {
    // Do something with your date!
  }
}

Use one of the Builder classes to create a PickerDialog with a theme:

DatePickerBuilder dpb = new DatePickerBuilder()
    .setFragmentManager(getSupportFragmentManager())
    .setStyleResId(R.style.BetterPickersDialogFragment);
dpb.show();

Also for another example you can visit Caldroid and use as follows:

To embed the Caldroid fragment in your activity, use below code:

CaldroidFragment caldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
Calendar cal = Calendar.getInstance();
args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
caldroidFragment.setArguments(args);

FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendar1, caldroidFragment);
t.commit();