Android 电视应用程序 - 无法 select 使用遥控器列出项目

Android TV App - unable to select list item with remote

目前我正在开发 Android 电视应用。

我已经使用了Android 靠背支持库。

我已经添加了一个 ListView,但我无法 select 使用真实设备的遥控器从 listView 中获取任何项目。但是,在鼠标的帮助下,我可以 select 我的 Android 虚拟设备上的 listView 项目。

这是我的 listView 示例代码:

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

这里,arrayViewOrders 是我的 ArrayList,它包含从 JSON 网络服务接收到的数据。

这是我的 JSON 回复:

{
   "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"
      }
   ]
}

我还在 AndroidManifest.xml 文件中添加了以下功能:

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

所以,我的问题是:如何在遥控器的帮助下select任何东西(即列表项、按钮)在真实设备中?

经过大量的研发,我终于找到了解决方案。

这是我使用 Android 电视遥控器进行定向导航的解决方案。

首先,您必须保持对以下任何一项(即 ButtonTextView 等)的关注。

此外,您还必须应用它的 nextFocusDownnextFocusLeftnextFocusRightnextFocusUp 属性,这样当您点击电视时它就会触发相关事件远程导航按钮。

<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>

更多信息可以参考:

  1. Android User Interface Design: The Basics of Control Focus Order,
  2. Creating TV Navigation.