Is there any way to disable writing inside a date picker using keyboard? As I just want the plus and minus signs to be used to set the date. thanks in advance.
Asked
Active
Viewed 7,658 times
14
-
4Why are you planning on breaking default user interaction? Expected behavior does not work anymore and it will confuse and/or annoy your users... – Veger Nov 20 '12 at 10:58
-
Because I have constrains on the input date from the user – Android Developer Nov 20 '12 at 10:59
-
So check if the input date is conform your constraints after the user choose a new date, and notify the user when it is not... – Veger Nov 20 '12 at 11:00
4 Answers
24
myDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);

Tkingovr
- 1,390
- 16
- 33
-
Do you know how to do this for DatePickerDialog, if API level is lower than 11? – Mario Kutlev Nov 05 '13 at 11:23
-
-
1@Antigona try this: myDatePickerDialog.getDatePicker().setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS); – user1851212 Jul 03 '14 at 11:57
5
dp.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
is the best way to do so.
You can check this also

Community
- 1
- 1

Rand Halim
- 87
- 1
- 8
3
Calendar start = Calendar.getInstance();
int Year = DatePicker.getYear();
int Month = DatePicker.getMonth();
int Day = DatePicker.getDayOfMonth();
start.set(Year, Month, Day);
// DayDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
Date periodDate = start.getTime();
int daysToAdd = 280;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH,daysToAdd );
System.err.println("-----" +cal.getTime());
int AfterCalc = cal.getTime().getYear()+1900;
System.err.println("-----" + AfterCalc);
int AfterCalc2 = cal.getTime().getMonth();
System.err.println("----" + AfterCalc2);
0
Best option for stopping manual editing in DatePickerDialog items is using set the descendantFocusability . You can add it in code or in your dialog style file.

Habibur Rahman Ovie
- 291
- 2
- 6