Android TV 应用 - 无法使用遥控器选择列表项 [英] Android TV App - unable to select list item with remote
问题描述
目前我正在开发 Android TV 应用.
Currently I am working on Android TV app.
我使用过 Android Lean 支持库.
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 网络服务接收的数据.
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.
首先,您必须保持以下任何一项(即Button
、TextView
等)的焦点.
Firstly, you have to keep focus of any one of items (i.e. Button
, TextView
, etc.) as below.
而且,你必须应用它的 nextFocusDown
、nextFocusLeft
、nextFocusRight
&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>
更多信息可以参考:
这篇关于Android TV 应用 - 无法使用遥控器选择列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!