1

I am using showNativePicker() in my Calendar application and when I am selecting a date it will only display current date so how can I manage it to display selected date in showNativePicker() method? Thanks in advance.

This is my code:-

    try{
           Display.getInstance().showNativePicker(Display.PICKER_TYPE_DATE,PivDisplayCalendar.this, value, metaData);
           Storage.getInstance().writeObject("Date", value);
           Log.p(value.toString());
           Dialog.show("Selected Date", value.toString(), "OK", "");
   } 
           catch(Exception e) {
                         e.printStackTrace();
             }
Gaurav Takte
  • 607
  • 5
  • 22
  • The [class documentation](https://www.codenameone.com/javadoc/com/codename1/ui/Display.html#showNativePicker-int-com.codename1.ui.Component-java.lang.Object-java.lang.Object-) shows that method returning a value. Passing `value` as a parameter has no effect on the subsequent state of variable `value` – spacepickle Apr 21 '17 at 08:27
  • But when I am printing value in a log then it will display the current date. @spacepickle – Gaurav Takte Apr 21 '17 at 08:30
  • I mean use something like `value = ...` see [this answer](http://stackoverflow.com/a/23622491/2842227) for why you shouldnt use this method directly though – spacepickle Apr 21 '17 at 08:52
  • I am testing this project on physical device and the native picker is also working properly But, I just want to ask is there any method which is use to display selected date through picker. – Gaurav Takte Apr 21 '17 at 09:18

1 Answers1

2

You are not capturing the value returned by the call to showNativePicker()

Here is an example piece of code. Notice the assignment statement in the second line. You may need to cast/convert this as the method returns Object

try {
  value = Display.getInstance().showNativePicker(Display.PICKER_TYPE_DATE,PivDisplayCalendar.this, value, metaData);
  Storage.getInstance().writeObject("Date", value);
  Log.p(value.toString());
  Dialog.show("Selected Date", value.toString(), "OK", "");
} catch(Exception e) {
  e.printStackTrace();
}
spacepickle
  • 2,678
  • 16
  • 21