0

I have an app with a very simple TV layout consisting of 2 web links (android:autoLink="web") and a text label. It renders like this:

http://yahoo.com

non focusable label

http://google.com

When the screen is loaded for the 1st time, I click d-pad down button and and the focus goes to the 1st link (yahoo.com). I then click d-pad down again expecting it to focus on google.com. Instead, the screen doesn't change and no focus is shown. If I click d-pad down again the focus finally arrives on google.com. This happens only 1st time the screen is loaded, if I keep clicking d-pad up/down the focus moves between 2 web links as expected. I'm looking for help figuring out why the focus doesn't behave as expected the 1st time. Thanks.

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "http://yahoo.com"
        android:autoLink="web"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="non focusable label"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "http://google.com"
        android:autoLink="web"
        />

</LinearLayout>
alexbtr
  • 3,292
  • 2
  • 13
  • 25

1 Answers1

0

Looks like you a losing the focus at some point.

You need to add to the view which is not supposed to be focused this:

android:focusable="false"
android:focusableInTouchMode="false"

The second thing to add is the focus directions for the next view that needs to be focused like this:

android:nextFocusDown="@+id/link_two"
android:nextFocusUp="@+id/link_one"

Which means the focused views need to have IDs.

The final solution for you:

 <TextView
        android:id="@+id/link_one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "http://yahoo.com"
        android:autoLink="web"
        android:nextFocusDown="@+id/link_two"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="non focusable label"
        android:focusable="false"
        android:focusableInTouchMode="false"
        />

    <TextView
        android:id="@+id/link_two"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "http://google.com"
        android:autoLink="web"
        android:nextFocusUp="@+id/link_one"
        />
  • Thanks Andrei, I did try all of these but it still doesn't help. The clue here is that it works fine 2nd time around which means it is all setup correctly with the focus etc. There is something else which is going on here. – alexbtr Sep 29 '20 at 02:26