1

I am developing an app using leanback architecture where a certain custom view is not focused using the dpad of remote.

The onFocus() of the custom view doesn't get called in FireStick version 3(Android API 28) . The same code gets triggered on lower versions( < Android API 28)

The custom view is a ListRow for showing genres of movies which is being fed data by GenrePresenter.

genrePresenter = new GenrePresenter(new GenrePresenter.viewListener() {
            @Override
            public void onClick(View view, String selected) {
                ((HomeFYCActivity) getActivity()).showAdapter(viewModel.genreList, selected);
            }

//THIS DOES NOT GET TRIGGERED ON API 28
            @Override
            public void onFocus(View view, Boolean hasFocus) {
                // NEED TO SET FOCUS HERE 
            }
        }, "ALL GENRES");

        header = new HeaderItem("NOW PLAYING");
        genreRow = new ListRow(header, genreRowAdapter);

But instead the HeaderItem gets the focus.

Same code works on < Android API 28

The remote trackpad is used to select the other views

EDIT genrePresenter listener code

    public interface viewListener {
        void onClick(View view, String selected);
        void onFocus(View view, Boolean hasFocus);
    }

And how i invoke the listener

        ((ShowCard) viewHolder).tvGenre.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                viewListener.onFocus(v, hasFocus);
            }
        });
Subhasmith Thapa
  • 884
  • 7
  • 11
  • Can you share, GenrePresenter.viewListener() code. – AndroidDev Jul 08 '21 at 14:42
  • @Velu have added the genrepresenter code. Let me know if you need more info – Subhasmith Thapa Jul 09 '21 at 03:47
  • Seems like you are setting focusChangeListener to textView, tvGenre, textView by default is not focusable, set the focusable property to true or setOnFocusChangeListener on the viewHolder itself, and again make sure that you have set focusable property to true. And I believe, to see the focus/unfocus change you have defined a color change. – AndroidDev Jul 09 '21 at 05:13
  • i tried replacing the textview with edittext here and still focus was not there, I will try putting the focusable property to viewholder itself and check, but i am getting confused is because same thing works on below API 28. and doesn't work above API 28. ANything i am missing? @Velu – Subhasmith Thapa Jul 09 '21 at 05:17
  • That's weird. API level for this issue shouldn't be a problem. Are you testing in emulator or the real device? , run this sample app from google https://github.com/android/tv-samples, the Accessibility demo module and see if the same issue is there in that device. – AndroidDev Jul 09 '21 at 05:44
  • i am running on FireStick V3 on a television. @Velu – Subhasmith Thapa Jul 09 '21 at 06:13
  • 1
    @Velu solved it – Subhasmith Thapa Jul 09 '21 at 07:41

1 Answers1

1

Hi After days of rigorous trial and error i found out that my XML's parent LinearLayout had to be set as

    android:clickable="false"
    android:focusable="false"

and the element which is inside the parent in my case a textview had to be defined as

   android:clickable="true"
   android:focusable="true"
   android:focusableInTouchMode="true"

I hope this answer saves your time.

Amen

Subhasmith Thapa
  • 884
  • 7
  • 11