Android TV App-无法选择带有遥控器的列表项 [英] Android TV App - unable to select list item with remote

查看:340
本文介绍了Android TV App-无法选择带有遥控器的列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在开发Android TV应用.

Currently I am working on Android TV app.

我已经使用了Android Lean back支持库.

I have used Android Lean back support library.

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

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.

这是我的listView的示例代码:

Here is my sample code of listView:

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

在这里,arrayViewOrders是我的ArrayList,其中包含从JSON Web服务接收的数据.

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

这是我的JSON响应:

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

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

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?

推荐答案

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

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

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

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

首先,您必须保持以下任何一项(例如ButtonTextView等)的焦点.

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

而且,您还必须应用其nextFocusDownnextFocusLeftnextFocusRight和& nextFocusUp属性,以便在您单击电视远程导航按钮时将触发其相关事件.

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用户界面设计:控制焦点顺序的基础
  2. 创建电视导航.
  1. Android User Interface Design: The Basics of Control Focus Order,
  2. Creating TV Navigation.

这篇关于Android TV App-无法选择带有遥控器的列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆