android中怎么设置一个日期的自定义对话框
1个回答
2016-12-08 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
在用户点击输入框或者输入框获得焦点的时候弹出来DatePickerDialog,用户点击设定按钮,将日期填写到输入框。
下面直接上代码:
[html] view plain copy print?
<EditText
android:id="@+id/Birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:inputType="none"//不显示系统输入键盘
android:layout_weight="1" >
</EditText>
[java] view plain copy print?
birthday = (EditText)findViewById(R.id.Birthday);
birthday.setInputType(InputType.TYPE_NULL); <span style="font-family: Arial, Helvetica, sans-serif;">//不显示系统输入键盘</span>
birthday.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(hasFocus){
Calendar c = Calendar.getInstance();
new DatePickerDialog(ProfileActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
birthday.setText(year+"/"+(monthOfYear+1)+"/"+dayOfMonth);
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();
}
}
});
birthday.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar c = Calendar.getInstance();
new DatePickerDialog(ProfileActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
birthday.setText(year+"/"+(monthOfYear+1)+"/"+dayOfMonth);
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();
}
});
下面直接上代码:
[html] view plain copy print?
<EditText
android:id="@+id/Birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:inputType="none"//不显示系统输入键盘
android:layout_weight="1" >
</EditText>
[java] view plain copy print?
birthday = (EditText)findViewById(R.id.Birthday);
birthday.setInputType(InputType.TYPE_NULL); <span style="font-family: Arial, Helvetica, sans-serif;">//不显示系统输入键盘</span>
birthday.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(hasFocus){
Calendar c = Calendar.getInstance();
new DatePickerDialog(ProfileActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
birthday.setText(year+"/"+(monthOfYear+1)+"/"+dayOfMonth);
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();
}
}
});
birthday.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar c = Calendar.getInstance();
new DatePickerDialog(ProfileActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
birthday.setText(year+"/"+(monthOfYear+1)+"/"+dayOfMonth);
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询