Aamir Shah Aamir Shah - 5 months ago 285
Android Question

How to make edit text not editable but clickable in JAVA

Is it possible to make edit text clickable but not editable.

I don't want it to be editable (Neither should the keyboard come up nor should we be able to change the hint)

Actually I want to use Edit text simply as an image with a hint (which cannot be changed). I know the actual way was to use an image view and one text view, but i want it to try with edit text coz i'll then be using only one view instead of 2. Also every thing is dynamic so no XML.

For the above requirement the solution in XML is

android:editable="false"
but i want to use this in Java.

But,

If I use :-

et.setEnabled(false);


or

et.setKeyListener(null);


It makes the edit text not EDITABLE but at the same time it makes it non clickable as well.

Any thoughts,.....Thanks :)

Answer

The trick here is :-

et.setFocusable(false);
et.setClickable(true);
Comments