androidandroid-edittexttouch-eventselectable

Android EditText - Editable but not Selectable?


Is it possible to make an EditText editable but not selectable? I want to be able to edit a bit of text, then drag it around the page. It works but while you're dragging it, that counts as a long click, so it selects some of the text.

Will I have to do something like make another view appear when I click on the EditText, have that capture the touch events instead, then hide it when the event action is up and return focus to the editText? That seems hacky/overly complicated.


Solution

  • I found a slightly less hacky solution than the one I mentioned above, and then tried (and it didn't work), but this does work:

    first do this,

    image_text.cancelLongPress();
    

    which apparently cancels any inherited click, not just the long click, i.e. it shows the cursor, and it doesn't select any text, but it also doesn't bring up the keyboard, but that's easy:

    View v = activity.getWindow().getCurrentFocus();
            if (v != null) {
                InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(v, 0);
            }