Search code examples
androidandroid-studioandroid-edittextandroid-buttononlongclicklistener

Button & EditText setOnLongClickListener bugs


I have some views in my program which I would want the user to drag. One of them is a Button and another is an EditText. I would like the Button to be unclickable and the EditText to be unenabled, but, still be draggable (activate the onLongClick method). How can I do this?

Implementation code below:

//The button
views.add(new Button(this));
...
views.get(views.size() - 1).setOnLongClickListener(this);
views.get(views.size() - 1).setClickable(false);

//The EditText
views.add(new EditText(this));
...
views.get(views.size() - 1).setEnabled(false);
views.get(views.size() - 1).setLongClickable(true);
views.get(views.size() - 1).setOnLongClickListener(this);

P.S - added to the EditText setLongClickable(true) but it still didn't work...

App work example (as you can see, other views drag regularly, the buttons drags too but is still clickable and the EditText is unenabled but also undruggable)

Thanks in advance!


Solution

  • Checked this problem! Instead of setOnLongClickListener I'm using setOnTouchListener in wich I make startDragAndDrop, and for unenabling the EditText and still dragging it I used setFocusable(false). Now it's working even better. New implementation