Android TV App - 无法选择远程

时间:2016-01-11 11:45:40

标签: android avd android-tv leanback

目前我正在使用Android TV应用。

我使用过Android精益支持库。

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

以下是listView的示例代码:

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

此处,arrayViewOrders是我的ArrayList,其中包含从JSON webservice收到的数据。

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

所以,我的问题是:如何在远程帮助下在真实设备中选择(例如列表项,按钮)

1 个答案:

答案 0 :(得分:5)

最后,在经过大量研发后,我得到了解决方案。

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

首先,您必须保持任何一个项目的焦点(例如ButtonTextView等),如下所示。

此外,您必须应用其nextFocusDownnextFocusLeftnextFocusRight&amp; 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 User Interface Design: The Basics of Control Focus Order
  2. Creating TV Navigation