How to prevent the user from typing in Edittext, but allow clicking on it to open a Datepicker?

Asked

Viewed 593 times

2

I have an Edittext that when clicking on it opens a Datepicker, how to prevent the user from typing in Edittext? I tried to use edtData.setEnable(false) but clicking on editText nothing happens.

2 answers

2

Add the following to Edittext:

android:focusable="false"

This will prevent Edittext from receiving phocus, not allowing you to type in it.

Alternatively use a Textview instead of Edittext.

For Textview to look like an Edittext use:

style="@android:style/Widget.EditText"
  • thanks, that’s exactly what I wanted.

  • Very good solution

1

To avoid editing in Edittext set Keylistener to null

edtData.setKeyListener(null);
  • That doesn’t work.

  • You’re right, thank you, I typed wrong, I just corrected my answer, hugs

  • Yes, it already works and is an interesting solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.