目前我正在开发 Android TV 应用。
我使用过 Android Lean back 支持库。
我已经添加了一个 ListView
,但我无法使用真实设备的 Remote 从 listView 中选择任何项目。但是,我可以借助鼠标在我的 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" />
所以,我的问题是:如何在 Remote 的帮助下在真实设备中选择任何内容(即列表项、按钮)?
最佳答案
经过大量的研发,我终于找到了解决方案。
这是我使用 Android TV Remote 进行定向导航的解决方案。
首先,您必须保持对以下任何一项(即 Button
、TextView
等)的关注。
此外,您还必须应用其 nextFocusDown
、nextFocusLeft
、nextFocusRight
和 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>
更多信息,您可以引用:
关于Android TV 应用程序 - 无法使用 Remote 选择列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34720761/