Reputation: 217
I have created dynamic text view at table row in table layout.
I want to highlight theh current row while I click row in table layout.
How can this be done?
Upvotes: 1
Views: 3790
Reputation: 13501
Below 2 lines should work fine. When creating the rows in a method
row.setFocusable("true");
row.setFocusableInTouchMode("true");
Upvotes: 1
Reputation: 4954
The following layout options worked for me to make a table row clickable and respond visually like a button:
<TableRow style="@style/PlanAttribute" xmlns:android="http://schemas.android.com/apk/res/android"
android:focusable="true"
android:focusableInTouchMode="true"
android:onClick="onRowSelected"
android:clickable="true">
...
PlanAttribute style:
<style name="PlanAttribute">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@drawable/divider_drawable</item>
</style>
divider_drawable.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/divider_down"
android:gravity="fill"/>
</item>
<item android:state_focused="true">
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/divider_selected"
android:gravity="fill"/>
</item>
<item
android:state_focused="false"
android:state_pressed="false">
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/divider"
android:gravity="fill"/>
</item>
</selector>
Upvotes: 0