Android TV App - unable to select list item with remote
Asked Answered
E

1

6

Currently I am working on Android TV app.

I have used Android Lean back support library.

I have added one ListView, but I can not able to select any of the item from listView with real device's remote. However, I can able to select item of listView on my Android Virtual Device with the help of mouse.

Here is my sample code of listView:

customViewOrders = new CustomViewOrders(getActivity().getBaseContext(), arrayViewOrders);
lstViewOrder.setAdapter(customViewOrders);

Here, arrayViewOrders is my ArrayList which contains data received from JSON webservice.

Here is my JSON Response:

{
   "order":[
      {
         "0":"13829CF",
         "gen_id":"13829CF",
         "1":"17534CF",
         "2":"Complete",
         "ord_status":"Complete",
         "3":"Online Preview",
         "sta_name":"Online Preview",
         "4":"2015-10-27 00:00:00",
         "image":"cinereel",
         "placed_from":"web"
      }
   ]
}

I have also added following features in AndroidManifest.xml file:

<uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false" />
<uses-feature
    android:name="android.hardware.faketouch"
    android:required="true" />

So, my question is: how to select anything (i.e. list item, button) in real device with the help of remote?

Excite answered 11/1, 2016 at 11:45 Comment(2)
Please add JSON response you are getting..Karakorum
@Kamal - I have added JSON response.Excite
E
9

Finally I got the solution after lots of R&D.

Here is the my solution for directional navigation using Android TV remote.

Firstly, you have to keep focus of any one of items (i.e. Button, TextView, etc.) as below.

And also, you have to apply its nextFocusDown, nextFocusLeft, nextFocusRight & nextFocusUp properties, so that it will fire its relevant event when you click TV remote navigation buttons.

<Button
    android:id="@+id/btnSignout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tvUserName"
    android:layout_marginTop="2dp"
    android:layout_toLeftOf="@+id/ivUser"
    android:width="100dp"
    android:nextFocusRight="@+id/ivUser" <!-- On click of right arrow button, focus will be move to ivUser id -->
    android:nextFocusUp="@+id/tvUserName" <!-- On click of up arrow button, focus will be move to tvUserName id -->
    android:text="@string/signout"
    android:textAppearance="?android:textAppearanceMedium">

    <requestFocus></requestFocus>

</Button>

For more information, you can refer to:

  1. Android User Interface Design: The Basics of Control Focus Order,
  2. Creating TV Navigation.
Excite answered 13/1, 2016 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.