Problem using a DateField...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, July 6, 2005 04:37 AM

i can't seem to capture what the user inputs inside my datefield, since whenever i invoke the getDate() function within my commandlistener the datefield resets to its original value(which is the current date)... here's my code: class DateInputForm extends Form implements CommandListener{ private final SalesMIDlet m; private Date currentDate; private Calendar cal; private DateField dateField; public DateInputForm(SalesMIDlet m){ super("Specify Date"); this.m=m; currentDate=new Date(); cal=Calendar.getInstance(); dateField=new DateField("Enter Date: ",DateField.DATE); dateField.setDate(curre   More>>

i can't seem to capture what the user inputs inside my datefield, since whenever i invoke the getDate() function within my commandlistener the datefield resets to its original value(which is the current date)...

here's my code:

			
class DateInputForm extends Form implements CommandListener{

private final SalesMIDlet m;

private Date currentDate;
private Calendar cal;

private DateField dateField;

public DateInputForm(SalesMIDlet m){
super("Specify Date");

this.m=m;

currentDate=new Date();
cal=Calendar.getInstance();

dateField=new DateField("Enter Date: ",DateField.DATE);
dateField.setDate(currentDate);

append(dateField);

addCommand(new Command("Test",Command.ITEM,1));
setCommandListener(this);
}

public void getDate(){
}

public void commandAction(Command c,Displayable d){
if(c.getCommandType()==Command.ITEM){
Date date=new Date(dateField.getDate().getTime());
MyDate mydate=new MyDate(date);
System.out.println(mydate.getDay());
System.out.println(mydate.getMonth());
System.out.println(mydate.getYear());
}
}
}


is there something wrong with my code????    <<Less

Re: Problem using a DateField...

Posted By:   Anonymous  
Posted On:   Thursday, August 4, 2005 08:30 AM


class DateInputForm extends Form {


private Date currentDate;


private Calendar cal;


private DateField dateField;


public DateInputForm(){

super("Specify Date");


currentDate=new Date();

cal=Calendar.getInstance();



dateField=new DateField("Enter Date: ",DateField.DATE);

dateField.setDate(currentDate);


append(dateField);


addCommand(CMD_TEST);


}



}




that was the form for holding date



now create it's instance upon clicking some command in your main form or display directly the form


put a test command in your form


and simply

//in some other command where f is an instance of your class

create f;



f = new DateInputForm();

f.setCommandListener(this);




and then




if(c==CMD_TEST)

{


Date date=new Date(f.dateField.getDate().getTime());




}




it will work
About | Sitemap | Contact