implementation 'com.savvi.datepicker:rangepicker:1.3.0'
activity_main. xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.savvi.rangedatepicker.CalendarPickerView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:scrollbarStyle="outsideOverlay"
app:tsquare_orientation_horizontal="false"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp"/>
<Button
android:id="@+id/get_selected_dates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Selected Dates"
tools:layout_editor_absoluteX="229dp"
tools:layout_editor_absoluteY="447dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dateselected"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity. java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.savvi.rangedatepicker.CalendarPickerView;
import com.savvi.rangedatepicker.SubTitle;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import androidx.appcompat.app.AppCompatActivity;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
CalendarPickerView calendar;
Button button;
private TextView datesSelected;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
datesSelected=(TextView)findViewById(R.id.dateselected);
final Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 10);
final Calendar lastYear = Calendar.getInstance();
lastYear.add(Calendar.YEAR, - 10);
calendar = findViewById(R.id.calendar_view);
button = findViewById(R.id.get_selected_dates);
ArrayList<Integer> list = new ArrayList<>();
list.add(4);
//calendar.deactivateDates(list);
ArrayList<Date> arrayList = new ArrayList<>();
SimpleDateFormat dateformat = new SimpleDateFormat("dd-MM-yyyy");
calendar.init(lastYear.getTime(), nextYear.getTime(), new SimpleDateFormat("MMMM, YYYY", Locale.getDefault())) //
.inMode(CalendarPickerView.SelectionMode.MULTIPLE);
calendar.scrollToDate(new Date());
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(MainActivity.this, "list " + calendar.getSelectedDates(), Toast.LENGTH_LONG).show();
datesSelected.setText("");
ArrayList<Date>selectedDates = (ArrayList<Date>)calendar.getSelectedDates();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
for(int i = 0; i< selectedDates.size(); i++)
{
Date tempDate = selectedDates.get(i);
String formattedDate = sdf.format(tempDate);
datesSelected.append(formattedDate);
//Toast.makeText(MainActivity.this, "list " + formattedDate, Toast.LENGTH_LONG).show();
//Following if is added to avoid adding comma after the last date.
datesSelected.append("<br/>");
}
}
});
}
private ArrayList<SubTitle> getSubTitles() {
final ArrayList<SubTitle> subTitles = new ArrayList<>();
final Calendar tmrw = Calendar.getInstance();
tmrw.add(Calendar.DAY_OF_MONTH, 1);
subTitles.add(new SubTitle(tmrw.getTime(), "₹1000"));
return subTitles;
}
}
```