我有一个编辑文本框,调用了ontouchlistener后会显示一个自定义对话框。当我点击setdate按钮时,日期选择器上的日期应设置在编辑文本框中,并且对话框应该关闭。但我不知道如何从日期选择器中获取日期并将其设置在编辑文本框中。我在date.init(year,monthOfYear,dayOfMonth,new MyOnDateChangedListener())中遇到错误,错误是:Multiple 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;
}