6

目前我正在开发 Android TV 应用程序。

我使用了 Android Lean 支持库。

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

这是我的 listView 示例代码:

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

arrayViewOrders是我的 ArrayList,其中包含从 JSON Web 服务接收到的数据。

这是我的 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" />

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

4

1 回答 1

9

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

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

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

此外,您必须应用其nextFocusDownnextFocusLeftnextFocusRight&nextFocusUp属性,以便在您单击电视远程导航按钮时触发其相关事件。

<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 用户界面设计:控制焦点顺序的基础知识
  2. 创建电视导航
于 2016-01-13T08:27:46.070 回答