问题
Currently I am working on Android TV app.
I have used Android Lean back support library.
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.
Here is my sample code of listView:
customViewOrders = new CustomViewOrders(getActivity().getBaseContext(), arrayViewOrders);
lstViewOrder.setAdapter(customViewOrders);
Here, arrayViewOrders
is my ArrayList which contains data received from JSON webservice.
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"
}
]
}
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?
回答1:
Finally I got the solution after lots of R&D.
Here is the my solution for directional navigation using Android TV remote.
Firstly, you have to keep focus of any one of items (i.e. Button
, TextView
, etc.) as below.
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:
- Android User Interface Design: The Basics of Control Focus Order,
- Creating TV Navigation.
来源:https://stackoverflow.com/questions/34720761/android-tv-app-unable-to-select-list-item-with-remote