1

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?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
John
  • 217
  • 2
  • 7
  • 13
  • possible duplicate of [How can I highlight the table row on click?](http://stackoverflow.com/questions/4075356/how-can-i-highlight-the-table-row-on-click) – Lekensteyn Apr 05 '12 at 19:19

2 Answers2

1

Below 2 lines should work fine. When creating the rows in a method

row.setFocusable("true");
row.setFocusableInTouchMode("true");
Ashishkumar Singh
  • 3,580
  • 1
  • 23
  • 41
ngesh
  • 13,398
  • 4
  • 44
  • 60
0

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>
sleep
  • 4,855
  • 5
  • 34
  • 51