Android TV: RowsFragment item click not working in few cases
Asked Answered
R

1

7

I'm working on an Android TV application and I'm facing a weird issue related to the item click listeners: everything works fine but sometimes the click is not propagated, very likely the listener is not set.

I have subclassed RowsFragment and I'm displaying my images with rows of 6 elements: it means each row of the grid is actually a row in the adapter, even if visually the photos have the same month. Please have a look at the image to have a better understanding.

enter image description here

Now the issue: when I start the application and I scroll down, the first row which is not visible in the image above (so the fourth row, since here 3 rows are rendered), doesn't get my "clicks", nothing happens. This might be true also for the 5th, 6th, ... rows but then (I didn't recognize a pattern) rows start to be clickable again (i.e. 8th, 9th, ..) The first 3 rows are always clickable as well.

If I scroll up again and those rows which were not clickable appear on the screen again, now they are clickable.

In the onCreate of the fragment, I call:
setOnItemViewClickedListener(new ItemViewClickedListener());
and according to the documentation this should override the listener set by the single item view. It's also suggested to set one listener, not both: in fact I just set this one for the fragment.

In the Presenter class of the single row item, I have tried to add a click listener in the onCreateViewHolder for the view and I have found out when the issue occurs, this listener is called.

So it seems under some circumstances, the overall fragment listener does not override the view listener or it's not set at all.

What also worries me about this issue, is that I'm not able to reproduce it in debug mode when I set breakpoints and I stop the scrolling animation.

I'm using the latest Leanback version:

compile 'com.android.support:leanback-v17:25.3.1'

The issue is reproducible on the Nvidia Shield TV (Android 7.0), not sure on other devices.

Update: what's also interesting is the fact that when an item is not clickable in one row, I would expect all the items in the same row to be not clickable. Instead it's not the case, some are clickable, some are not.

Update 2: it seems ListRowPresenterItemBridgeAdapter method onBind, in some occasions, find getOnItemViewClickedListener to return null, so the item click listener is not set. That's weird because the listener is set for the main RowsFragment class and it works fine for most of the items, also items in the same row of those ones not working.

As a workaround I have found this solution: subclass the ListRowPresenter and set a dummy click listener to it.

private class GroupedListRowPresenter extends ListRowPresenter {
    GroupedListRowPresenter(int focusZoomFactor) {
        super(focusZoomFactor);
    }

    @Override
    protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) {
        super.onBindRowViewHolder(holder, item);

        holder.setOnItemViewClickedListener(new BaseOnItemViewClickedListener() {
            @Override
            public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder
                    rowViewHolder, Object row) {
                Timber.d("item click from dummy listener: this should never happen!");
            }
        });
    }
}

I'm not comfortable with it, because I really don't like to set an empty click listener, even if I know it will get overridden.

Update 3: the issue is also reproducible with the sample application created by Android Studio, so it seems not related to something wrong in my code. For this reason I have filed a bug: https://issuetracker.google.com/issues/62443122

If you're affected by this issue as well, please star the issue above, so it will get more attention, thanks.

Roveover answered 18/5, 2017 at 13:57 Comment(5)
Thanks for posting your progress here. Had exactly the same issue and your 2nd update also fixed it for me. It feels really wrong though, I hope it won't break in future releases. Probably going to need to write a UI test for this >.<.Beaded
@Beaded I didn't have time so far, but I think I've seen the same issue in the sample project for Android TV created by Android Studio. I will double check about that: if that's the case it's going to be quick and easy to open an issue. Otherwise, since my project is not open, I need to find time to implement a sample project on github.Roveover
I've seen this as well. Rolling back to com.android.support:leanback-v17:24.2.1 fixed the issue for meSpurling
@ElvisD'Souza thanks, good to know. I'll mention it in the Google issue.Roveover
I have the same issue. Also on Nvidia ShieldDeerhound
P
4

I've experienced the same issue but updating to support library version 25.4.0 fixed this. Please note that from 25.4.0 you have to include

maven {
    url "https://maven.google.com"
}

in the repositories. See Support Library Setup.

Pun answered 13/6, 2017 at 13:19 Comment(3)
Yes, I've noticed the following comment in the release notes: BrowseFragment onItemClicked callbacks broken in 25.3.0. Since you have already tested it, I'll accept your answer. Thanks.Roveover
I can also affirm that the cause for this issue is the leanback support library 25.3.x. Downgrading/upgrading fixes the issue.Lomasi
this issue is still present in support library:28.0.0Parkerparkhurst

© 2022 - 2024 — McMap. All rights reserved.