i have a edit text box and i have call ontouchlistener it show a custom dialog and when i click setdate button the date on date picker should set on the edit text and the dialog should get dismiss. but i dont know how to get date from date picker and how to set in edit text box. i am getting error in date.init( year, monthOfYear, dayOfMonth, new MyOnDateChangedListener() ); and the error isMultiple markers at this line
– dayOfMonth cannot be resolved to a
variable
– year cannot be resolved to a variable
– monthOfYear cannot be resolved to a
variable
et4.setOnTouchListener(new OnTouchListener() {
final Dialog setdatedialog = new Dialog(DropboxActivity.this);
public void onClick(View v) {
}
public boolean onTouch(View arg0, MotionEvent arg1) {
setdatedialog.setContentView(R.layout.datedialog);
setdatedialog.setTitle("select date of puchase");
setdatedialog.setCancelable(true);
setdatedialog.show();
Button back = (Button)setdatedialog.findViewById(R.id.back3);
back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setdatedialog.dismiss();
}
});
Button setdate=(Button)setdatedialog.findViewById(R.id.setdate);
DatePicker date = (DatePicker)setdatedialog.findViewById(R.id.datePicker1);
class MyOnDateChangedListener implements OnDateChangedListener {
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth){
et4.setText( "" + dayOfMonth + "-" + (monthOfYear + 1) + "-" + year );
}
};
date.init( year, monthOfYear, dayOfMonth, new MyOnDateChangedListener() );
return false;
}
Define editText and Button in xml and below code in your activity:
Now add these two functions to call DatePicker Dialog and to set date in the Edittext
Define this globally:
This will help you to set date in the editText.Hope this will help you.