0

I have EditText which I want to disable and enable onLongClick, but I'm unable to long click on them after they are disabled. What do do?

This was the code I wrote for the purpose:

for (int j = 0; j < noOfDigits; j++) {
        final int k = j;

        etReference[j].setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if(etReference[k].isEnabled()) {
                    etReference[k].setEnabled(false);
                }
                else if(!etReference[k].isEnabled()){
                    etReference[k].setEnabled(true);
                }
                return false;
            }
        });
}
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
Abhijeet
  • 345
  • 1
  • 4
  • 15

1 Answers1

0

Disabled components means that it shouldn't fire interect events.

If you are really wanting to do that, you should setOnTouchEvent and parse a LongClick by yourself (DOWN + NOT MOVE + 500ms).

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • No, too complex, you should learn how to parse events based on its type. All I can say is that you should fire a postDelayed to a Handler on DOWN and cancel it if a move occurs, but be aware, move events are common than your think, so you should have some if based on the distance moved, something about 16dp works fine. – Marcos Vasconcelos Aug 22 '17 at 14:22
  • Check the answer theres a implementation of this method https://stackoverflow.com/questions/4324362/detect-touch-press-vs-long-press-vs-movement – Marcos Vasconcelos Aug 22 '17 at 14:26