Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Prevent Keyboard appearing for EditText that is not enabled

My activity has an EditText which is supposedly not editable until user clicks on edit button for the screen.

I did edit.setEnabled(false) but still a keyboard appears for the user and values can be added to the EditText in the screen via the keyboard even though the screen might look a bit greyed out. What else do I have to do to prevent editing of the EditText until user has specifically pushed an edit button.

Thanks, Steve

like image 842
barcodereader Avatar asked May 19 '11 23:05

barcodereader


People also ask

How do I hide the soft keyboard on android after clicking outside EditText?

This example demonstrates how do I hide soft keyboard on android after clicking outside edittext. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

Attention that setEditable is depecrated.

You can use :

setInputType(EditorInfo.TYPE_CLASS_TEXT)

To turn keyboard on.

setInputType(EditorInfo.TYPE_NULL)

To turn keyboard off.

like image 103
Tiago Almeida Avatar answered Oct 08 '22 08:10

Tiago Almeida