Reputation: 2244
I'm using this link for date picker, I want to show only Month in date picker. How can i achieve this?
and also know
Upvotes: 4
Views: 15618
Reputation: 43
This is the best option I think : https://github.com/DogusTeknoloji/compose-date-picker
Year Picker:
Month Picker:
ComposeCalendar(
minDate: Date? = null, // Set min selectable date
maxDate: Date? = null, // Set max selectable date
locale: Locale = Locale.getDefault(), // Set locale for localization
title: String = "", // Set title
listener: SelectDateListener, // Set Listener for selected date
showOnlyMonth: Boolean = false, // Display only month picker
showOnlyYear: Boolean = false, // Display only year picker
themeColor:Color = Color(0xFF614FF0), // Set picker color
negativeButtonTitle:String = "CANCEL", // Set negative button text
positiveButtonTitle:String = "OK" // Set positive button text
)
Upvotes: 2
Reputation: 1971
You may use the following lib: https://github.com/lutvie72/RackMonthPicker.
new RackMonthPicker(this)
.setPositiveButton(new DateMonthDialogListener() {
@Override
public void onDateMonth(int month, int startDate, int endDate, int year, String monthLabel) {
}
})
.setNegativeButton(new OnCancelMonthDialogListener() {
@Override
public void onCancel(AlertDialog dialog) {
}
}).show();
Upvotes: 3
Reputation: 669
easiest way, maybe not te purest one is to extend DatePickerDialog
all you need it to override onYearSelected
callback and then also newInstance
because if you don't do that it will produce DatePickerDialog
, not new YearOnlyPicker
object. Additionaly in newInstance
I've added showYearPickerFirst(true)
call but it can be done also from out side. Then you can use this dialog as original one. It's kind of hack but it's only way to achieve that without modifying library source code
here is class that extends DatePickerDialog
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
public class YearOnlyPicker extends DatePickerDialog {
public static YearOnlyPicker newInstance(OnDateSetListener callBack, int year,
int monthOfYear,
int dayOfMonth) {
YearOnlyPicker ret = new YearOnlyPicker();
ret.showYearPickerFirst(true);
ret.initialize(callBack, year, monthOfYear, dayOfMonth);
return ret;
}
@Override
public void onYearSelected(int year) {
super.onYearSelected(year);
notifyOnDateListener();
dismiss();
}
}
Upvotes: 0