Android DatePicker does not recognize when the year was changed by typing

I have a DatePicker that works pretty much as expected. EXCEPT, if instead of the +/- buttons the user enters fields At this point, although it shows the entered values, it gets information about what date was there before the user typed. As soon as the user presses + or - he is updated.

I see an update method that takes on values ​​that I don't want. I want to provoke it to revise its values ​​when the user clicks the continue button (not applicable to DatePicker). I can attach the listener to the loss of focus, but I don’t see what I can call to review its contents.

Any ideas are welcome.

EDIT DatePicker definitely updates its values ​​as soon as the user moves focus either from the entire object, or even between three fields. The question, I think, is how to divert attention from him when there is nothing else on the screen that can focus. I am trying to focus my Skip button, but for some reason it refuses focus. I would like to know more about this, if anyone knows.

+4
source share
2 answers

Just need clearFocus on a DatePicker. No need for hidden field.

final DatePicker dp = (DatePicker)v.findViewById(R.id.dpDate); dlg.setPositiveButton("Done", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dp.clearFocus(); String val = ""; int m = dp.getMonth() + 1; val = m + "/" + dp.getDayOfMonth() + "/" + dp.getYear(); mA.setmDOB(val); etAge.setText(AppHelper.calcAge(val, "y", false) + " (" + val + ")"); } }); 
+6
source

Repeat the focus ( requestFocus() ) of the DatePicker again in the onPress method of the Continue button.

0
source

Source: https://habr.com/ru/post/1342350/


All Articles