ANDROID: Highlight/Select with Trackball and when Touched
-
29-09-2019 - |
Question
My Android
application currently has TableLayout
with several TableRow
s containing an ImageView
then TextView
side-by-side.
Clicking any where on a TableRow
will load a new activity showing further info.
If I use the trackball, it will work its way through the rows, but I don't see which is currently selected so have no idea which TableRow
is selected when I click the button to load the activity
.
Likewise, when a user touches the screen with a finger, there is no highlight showing which one they selected.
I've searched with terms such as Highlight, Selected, Focus, but none of the pages I see returned have given me any insight into achieving what I require.
Using a TableLayout
is required I guess, it was just what I used and may not even be the best solution!
Any examples out there I can try to get this working??
Thanks! :)
Solution
You need to use selectors, for instance you have some view which holds view of you row, then you need to create selector like this
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/list_viewentry_focused" />
<item android:state_pressed="true" android:drawable="@drawable/list_viewentry_pressed" />
<item android:drawable="@drawable/list_viewentry_normal" />
</selector>
and put it in your drawables folder
then you need to set android:background @drawable/drawable_name