Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
vishalkheterpal
Posts: 92
Registered: 01-11-2011

Date-Picker

Hi

    I am working on 5.0 jde and i use datePicker in an application.But the Datepicker is not working properly.The "ok" and "Cancel" button is not working in the right way.If i click on the cancel button even then it select the date of the datepicker

My code is following--

DateTimePicker datePicker = DateTimePicker.createInstance(Calendar.getInstance(), "yyyy-MM-dd", null);
             datePicker.doModal();
             Calendar cal = datePicker.getDateTime();
             int month=cal.get(cal.MONTH);
             int year=cal.get(cal.YEAR);
             int date1=cal.get(cal.DATE);

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: 12-27-2010

Re: Date-Picker

doModal() returns true if the user selected OK and false if it was Cancel, so you need to be testing it.

Please use plain text.
Developer
Ebscer
Posts: 431
Registered: 08-31-2009
My Carrier: Verizon

Re: Date-Picker

Such as

 

 

DateTimePicker datePicker = DateTimePicker.createInstance(Calendar.getInstance(), "yyyy-MM-dd", null);
if(datePicker.doModal())
{
             Calendar cal = datePicker.getDateTime();
             int month=cal.get(cal.MONTH);
             int year=cal.get(cal.YEAR);
             int date1=cal.get(cal.DATE);
}

 

 


Read my thoughts on BlackBerry Development at news.ebscer.com
Please use plain text.
Contributor
gaurav2k11
Posts: 20
Registered: 03-04-2011
My Carrier: application developer

Re: Date-Picker

Hello sir i m using date picker in which i have to send from and to date to server ..

now by using the date picker i m getting date in this format ::: From Date :::net.rim.device.impl.ui.picker.datetime.DateTimePickerController@f51e86bf

that date in yyddmm format ...please tell me how to solve this problem i m using the following code:::

 

 

 

 

DateTimePicker datePicker1 = DateTimePicker.createInstance(Calendar.getInstance(), "yyyyMMdd", null);
 if(datePicker1.doModal())
 {
             Calendar cal = datePicker1.getDateTime();
             int month=cal.get(cal.MONTH);
             int year=cal.get(cal.YEAR);
             int date1=cal.get(cal.DATE);
             //String From = datePicker1.createInstance(Calendar.getInstance(), "yyyyMMdd", null);
             Dialog.alert("FromDate " + datePicker1);
             System.out.println("From Date :::"+datePicker1);
    ////         From Date :::net.rim.device.impl.ui.picker.datetime.DateTimePickerController@f51e86bf    
 }
 DateTimePicker datePicker2 = DateTimePicker.createInstance(Calendar.getInstance(), "yyyyMMdd", null);
 if(datePicker2.doModal())
 {
             Calendar cal = datePicker2.getDateTime();
             int month=cal.get(cal.MONTH);
             int year=cal.get(cal.YEAR);
             int date1=cal.get(cal.DATE);
             Dialog.alert("FromDate " + datePicker2);
             System.out.println("From Date :::"+datePicker2);
 }
 System.out.println("Inside date ...............");
      sPostdata = "{\"sid\":\""+ CompanyList.sid+ "\",\"cn\":\""+ CompanyList.selComp.getText()+"\",\"ln\":\""+LedgerName+"\",\"f\":\"datePicker1\",\"t\":\"datePicker2\",\"s\":\"5\",\"o\":\"11\",\"rs\":\"1\"}";

 

 this the post date in which i have to send from and to date ...

please tell me the solution ...

with regards

 

 

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: 12-27-2010

Re: Date-Picker

You need to use DateTimePicker.getDateTime(), which will return you a Calendar object. From there you can use some formatter (SimpleDateFormat will probably work) to get the date output the way you want.

Please use plain text.
Super Contributor
shahumang8
Posts: 306
Registered: 08-09-2010

Re: Date-Picker

Hi,

 

Check this code i hope this code usefull to...

 

 

 DateTimePicker datePicker = DateTimePicker.createInstance();
 datePicker.doModal();
 Calendar cal = datePicker.getDateTime();
 Date date = cal.getTime();
 SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm");                    date1=format.format(date);

 

------------------------------------------------------------

 

feel free to press the kudos button  on the left side to thank the user that helped you.
please mark posts as solved if you found a solution

 

 

Please use plain text.
Contributor
doc_taco
Posts: 13
Registered: 06-18-2010
My Carrier: na

Re: Date-Picker

That may have been in the past.  

int doModal() now returns type int.  0 indicates the user selected OK.  

Please use plain text.