[英]how to create calenderView as pop up window on edittext in android studio?
hello I want to show calender view as pop up to user so user can put date and it will appear on edit text. 你好,我想向用户显示日历视图,以便用户可以输入日期,日期将显示在编辑文本上。 Is it possible ?
可能吗 ?
Here is code for you. 这是给你的代码。 Write this code in your activity.
在您的活动中编写此代码。
public static class DateDialog extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
month = month + 1;
if (month < 10 && day < 10) {
txt_dob.setText(year + "-" + "0" + month + "-" + "0" + day);
} else {
txt_dob.setText(year + "-" + month + "-" + day);
}
}
}
code for onclick onclick的代码
txt_dob.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = new DateDialog();
newFragment.show(getActivity().getSupportFragmentManager(),
"datePicker");
}
});
It will show you pop-up and selected date is set on Textview. 它将显示弹出窗口,并在Textview上设置选定的日期。
Happy To Help 乐意效劳
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.