需要使EditText选日期类型的数据,选用DatePickerDialog无疑是最好的选择。
XML代码:
<EditText android:layout_width="200dp"
android:inputType="none"
android:layout_height="wrap_content"
android:id="@+id/editText_ProductionDate"
/>
Java代码:
editText_ProductionDate = findViewById(R.id.editText_ProductionDate);
editText_ProductionDate.setInputType(InputType.TYPE_NULL);
editText_ProductionDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
new DatePickerDialog(AddinputGoodsDetailActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
editText_ProductionDate.setText(year+"/"+(month+1)+"/"+dayOfMonth);
}
},calendar.get(calendar.YEAR),calendar.get(calendar.MONTH),calendar.get(calendar.DAY_OF_MONTH)).show();
}
});
|