1

enter image description hereI have implemented GridView on an Android TV app to show YouTube videos from a particular channel. What I want is on pressing the Ok key whichever Item is in focus it should be played and on keyDown GridView should scroll if it is the end of the list. If scrolling works then on item focus does not work and the item is not selected, if the item is selected and played then the GridView does not scroll. I am confused in this concept as how to make the GridView items work on focus. I am sharing my code what I have done, Hope somebody is able to solve my problem. I want normal functionality like mobile phone we scroll and select whichever Item we want to select in GridView, but here we do not have touchscreen only the remote controller. In current scenario item is selected but scrolling does not work.

<GridView
        android:descendantFocusability="afterDescendants"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:numColumns="4"
       android:id="@+id/gridview"
       android:layout_marginLeft="5dp"
       android:layout_marginBottom="5dp"
       android:layout_marginTop="5dp"
       android:layout_marginRight="5dp"
       android:verticalSpacing="5dp"
       android:horizontalSpacing="5dp"></GridView>


// bg_select 
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/bg_focused" android:state_focused="true"></item>
    <item android:drawable="@drawable/bg_round"></item>

</selector>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


        <LinearLayout
            android:focusable="true"
            android:id="@+id/card_view"
            android:layout_margin="16dp"
            android:background="@drawable/bg_select"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center"
            >
    <ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_margin="4dp"
       />

    <TextView
        android:layout_margin="16dp"
        android:textAlignment="center"
        android:textColor="#FFF"
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:text="Fragment List"/>
        </LinearLayout>

</LinearLayout>
piet.t
  • 11,718
  • 21
  • 43
  • 52
Paras Watts
  • 2,565
  • 4
  • 21
  • 46
  • Check this [SO post](https://stackoverflow.com/questions/29870223/keyboard-navigation-with-android-gridview-doesnt-scroll-grid). Maybe this could help, the difference is that this issue is using keyboard and not a remote control, but upon checking this documentation about [keyboard navigation](https://developer.android.com/training/keyboard-input/navigation.html), it also supports directional navigation same when using a [remote](https://developer.android.com/training/tv/start/navigation.html). Hope this helps. – MαπμQμαπkγVπ.0 Mar 08 '18 at 10:46

0 Answers0