Mygod Mygod - 1 year ago 178
Java Question

Readonly selectable EditText

I have an EditText that need to be switched between normal mode and readonly selectable mode (more specifically it's a kind of highlight mode where selection is set by

and user can't change the selection). The problem is that sometimes the selection is not showing up. And after I toggle EditText to readonly selectable mode then toggle it back, when I press somewhere the cursor moved but the soft keyboard isn't showing up.

Here's the code to toggle it to readonly selectable mode:

inputText.selectAll(); // for test purpose

Here's the code to toggle it back to normal mode:

inputText.setFocusable(true); // this line can be omitted according to the source code

It seems selecting texts works for the first time and after that it never works unless the application is restarted.

Answer Source

At last I decided to use another TextView containing exactly the same text and display that one (and hiding EditText) when I need to "disable" my EditText.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download