EditText ellipsize long text and then make the view editable on click/touch

495 Views Asked by At

I have EditText which I need to ellipsize and make sure the first characters are visible if the text is too long. But on click/touch event it should be editable and the cursor should be at the end of the line.

After searching the internet it seems that android:ellipsize="end" is not compatible with editable mode of the EditText. Indeed, if I set edittext.setKeyListener(null) ellipsize works, but then the view is not editable and i cannot set any onClickListener on it.

If i use setFocusable(false) instead of disabling KeyListener I do not get ellipsize effect.

My current code:

    v.setSelection(0);
    v.setFocusable(false);
    //v.setKeyListener(null);
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            v.setFocusable(true);
            v.setFocusableInTouchMode(true);
            v.setEnabled(true);
            v.setSelection(v.getText().length());
        }
    });

xml:

android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:singleLine="true"
1

There are 1 best solutions below

0
On

Can you make work around with some other views? Like show TextView for ellipsize and onclick of TextView show EditText instead of TextView and keep the cursor position to the end of EditText