3

I have a LinearLayout which needs to be clickable inside a NestedScrollView inside a CoordinatorLayout and almost all the time the first time I click it it simply doesn't work, I must click it another time.

Click error

Clickable LinearLayout:

<LinearLayout
            android:id="@+id/qr_code_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:clickable="true"
            android:focusable="true"
            android:background="?android:attr/selectableItemBackground"
            tools:ignore="UseCompoundDrawables">

EDIT: Okay this is very weird, if I wait some seconds before trying to click the View, it works the first time. It only fails if I click it just after scrolling to the bottom.

ColdFire
  • 6,764
  • 6
  • 35
  • 51
Grender
  • 1,589
  • 2
  • 17
  • 44
  • Maybe with the first click you make clickable true, then the second touch make it false, please check your generateQr() thoroughly, and let me know. – Elmira Frhn Jan 08 '18 at 16:32
  • 2
    The problem is in focus. First click well set focus and second will actually call onclick method. If you want to set `focusable` to `true` and still get first click the check the `setOnFocusChangeListener` in documentation. – Yupi Jan 08 '18 at 16:36
  • @ElmiraFrhn I have tried removing the line where I set clickable to `false` and the problem is still there. I don't think the problem is in that method. :/ – Grender Jan 08 '18 at 16:36
  • @Yupi I have set `focusable` to `true` because Android Studio suggest to do it if you also have `clickable=true`. Even if I remove `focusable=true` the problem is still present. – Grender Jan 08 '18 at 16:38
  • you will set focusable to false, clickable to true – propoLis Jan 08 '18 at 16:40
  • @propoLis If I do that, Android Studio suggests to set `focusable` back to `true`. Also, the problem is not solved. – Grender Jan 08 '18 at 16:41
  • Just updated the question. – Grender Jan 08 '18 at 21:17
  • Hey @Grender Did you find the solution? I tried every combination but none worked so far. – T.M Apr 15 '18 at 09:14
  • Unfortunately not, @T.M – Grender Apr 15 '18 at 19:52
  • your main thread is busy maybe you are doing heavy things such as I/O or network on main thread or maybe your layout is too heavy to inflate that you need to wait some seconds for UI response to click event. – ygngy May 11 '18 at 10:03

1 Answers1

2

I had the same problem. Inside the NestedScollView there was a RelativeLayout element needed to be clicked. As long I didn't scroll to the very bottom, the element could be clicked with a single click. If I would reach the bottom I needed two clicks, except if I waited a number of seconds.

The problem proved to be on the default layout_behavior of the AppBarLayout. I used the custom one suggested in the post below and the problem was solved.

onClick method not working properly after NestedScrollView scrolled

strat
  • 36
  • 5
  • Finally! Thanks a lot! The workaround until it gets fixed can be found [here](https://gist.github.com/chrisbanes/8391b5adb9ee42180893300850ed02f2). Seen [here](https://issuetracker.google.com/issues/66996774). – Grender May 12 '18 at 17:09