Button.LongClick triggers also Button.Click event / bug

Are you testing on real devices? If so, which?

10 and 11 for real devices, and 10 on genymotion emulator as well.

Try this:

Make a long click on one of the buttons and post a screenshot.
I don't believe it until I see it! :upside_down_face:

(Just tested on a Galaxy S3 / Android 4.3: same result.)

Generally, LongClick should be called LongTouch, because the event is executed while holding the button, not after releasing it. So I think clicking is press and release, then the Click event is triggered, whether the button is held long or short. However, in my opinion the event is wrongly named, which is misleading.

I get this on all my test devices (and there are a lot, 16 real devices: Android 4x, 5x, 7, 8.x, 9, 10, 11):

Found the difference. I had empty (not disabled) click and longclick event blocks in my editor. This was preventing the click event from firing.

This is really annoying because we are wasting an unnecessary amount of time.
You said you tested my aia, but it wasn't true.

We should remove all unnecessary and confusing posts here so as not to make it harder for Evan.

Actually I said

it works fine in my project

I disagree, it all serves to clarify the issue.

As I said, there was really no need to restart the discussion from the beginning.

I disagree, it was not clear where the problem lay in your original post, because you supplied so many different methods.

1 Like

Yes, and it is triggered after 400-403ms.

Blocks

buttonLongClick2.aia (3.6 KB)

1 Like

@Anke is right.

1 Like

So, this is the answer.

1 Like

No you said

"I have just tested → it".
You should have said "I have just tested → something"

@Anke, I have a strange situation in my sample app. Why does it work without additional flags, even though previous tests indicate an error. Could you take a look at this? All click events are successful.

I know the topic is old. The AI2 update is coming. I think a fix could be made to prevent the click event from being raised when long clicks. Since each click method has its own event, this can be separated.

From little experience, and from the description itself, it appears that it is enough to change from "return false;" to "return true;" in ButtonBase.java.

public abstract void click();

  // Override this if your component actually will consume a long
  // click.  A 'false' returned from this function will cause a long
  // click to be interpreted as a click (and the click function will
  // be called).
  public boolean longClick() {
    return false;
  }

  // OnClickListener implementation

  @Override
  public void onClick(View view) {
    click();
  }

The "fix" is simple, the problem has always been the fact that apps may have functionality that would be affected semantically by this change, effectively breaking them without a way to address it. A more complicated solution would involve having a property on the button to control the expected behavior.