Android Long Click vs. Default Click

705 Views Asked by At

I have an EditText that is focused and a Button that is not focused.

When I click the Button, the EditText loses focus.

When I long-click the Button, the EditText does not lose focus.

Whats the source of this behaviour? I want to achieve the long-click behaviour within a default click, is this possible?

1

There are 1 best solutions below

5
SpiritCrusher On

Long click behavior is for by default for ClipBoard actions . If you want to override it with Single click . You can do this as follows.

editText=(EditText)findViewById(R.id.txt);
    editText.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            // Do your stuff
            return true;
        }
    });
    editText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editText.performLongClick();

        }
    });

If you are doing it to just get rid of Focusing problem then its not the way.