开发者

Android DatePicker doesn't recognize when the year has been changed via typing

I have a DatePicker which works pretty much as expected EXCEPT when instead of using the +/- buttons, the user types in the fields. At that point, even though it's showing the values typed, it's getters are returning the info for whatever date was in there before the user was typing. As soon as the user hits a + or - it updates.

I see an update method that takes values, which is not what I want. I want to provoke it to re-examine its values when the user clicks on a "proceed" button (not related to the DatePicker). I can attach a listener to the loss of focus, but I don't see what I can call to get it to re-examine its contents.

All ideas welcome.

EDIT The DatePicker definitely updates its values as soon as the user moves focus either away from the entire Object or even between the three fields. The question, I guess, is how to force the focus away from it, when there isn't 开发者_Go百科anything else on the screen that can take focus. I'm trying to focus my proceed button, but it refuses to take focus for some reason. Would love to know more about that as well, if anyone knows.


Just need to clearFocus on 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 + ")");
 }
 });


Try focusing (requestFocus()) the DatePicker again on the onPress method of the proceed button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜