My app contains an EditText
object with some text in it. When the activity opens I don't want this EditText
to be editable (view only, no blinking cursor & no keyboard pop up). Then in order to edit, the user clicks on the EditText
(This brings back the blinking cursor and the keyboard pops up).
There should have been a function like setEditable(boolean)
. The editable XML attribute in EditText
is deprecated (The warning suggests using setInputType()
instead).
Is there a way to achieve this?
Final note: I have searched the internet for couple hours and this is the best I ended up with:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
editor = (EditText) findViewById(R.id.noteEditText);
editor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editor.setInputType(
EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
}
});
editor.setInputType(EditorInfo.TYPE_NULL);
...
}
This doesn't work as I intend. I have to double click in order to be able to edit (On first click the blinking cursor and the keyboard don't appear, in second click they do)