Добавьте атрибут android: inputType = "date" и android: onClick = "your_function", чтобы привязать щелчок по тексту редактирования к функции
Вот пример деятельности MainActivity.kt:
class MainActivity : Activity() {
lateinit var editTextDate: EditText;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
editTextDate = findViewById(R.id.edittext_date);
}
fun openPickerDate(view : View) {
val c = Calendar.getInstance()
val year = c.get(Calendar.YEAR)
val month = c.get(Calendar.MONTH)
val day = c.get(Calendar.DAY_OF_MONTH)
val dpd = DatePickerDialog(this, DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
editTextDate.setText("" + dayOfMonth + "/" + monthOfYear + "/" + year)
}, year, month, day)
dpd.show()
}
}
Вот макет activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/edittext_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="01/01/2018"
android:inputType="date"
android:onClick="openPickerDate"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>