Can anybody tell how to display year only in date picker in android
Thanks
private void showBirthDayPicker() {
int year = calendar.get(Calendar.YEAR);
final Dialog birthDayDialog = new Dialog(this);
birthDayDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
birthDayDialog.setContentView(R.layout.dialog_birthday);
Button okBtn = birthDayDialog.findViewById(R.id.btn_ok);
Button cancelBtn = birthDayDialog.findViewById(R.id.btn_cancel);
final NumberPicker np = birthDayDialog.findViewById(R.id.birthdayPicker);
np.setMinValue(year - 100);
np.setMaxValue(year - 15);
np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
setDivider(np, android.R.color.white);
np.setWrapSelectorWheel(false);
np.setValue(year-20);
np.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker numberPicker, int i, int i1) {
}
});
okBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
edtBirthDay.setText(String.valueOf(np.getValue()));
birthDayDialog.dismiss();
}
});
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
birthDayDialog.dismiss();
}
});
birthDayDialog.show();
}
xml
`enter code here`