Is there any solution, where I can write single onClick method for all rows in table in Android?
<p>my requirement is that, I have a table with multiple rows where by selecting single row should display its contents on screen. I figured out that by writing onClick() for every row its achievable, but its not feasible to write multiple onClick()'s for multiple rows. So is there any way to achieve this without writing multiple onClick()'s. </p>

<p>This is my XML for table:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
 &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/relativelayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" &gt;
&lt;ScrollView android:id="@+id/ScrollView01"  
       android:layout_height="100dp" android:layout_width="wrap_content"&gt;
    &lt;TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="wrap_content"
        android:background="#000000"
        android:stretchColumns="*"
        android:layout_height="100dp"
        android:scrollbars="horizontal"
         &gt;

        &lt;TableRow
            android:layout_margin="0.2dip"
            android:background="#000000" &gt;

            &lt;TextView
                android:layout_margin="0.2dip"
                android:background="#FFFFFF"
                android:text="@string/code" /&gt;

            &lt;TextView
                android:layout_margin="0.2dip"
                android:background="#FFFFFF"
                android:text="@string/name" /&gt;
        &lt;/TableRow&gt;

        &lt;TableRow
            android:layout_margin="0.2dip"
            android:background="#000000"
            android:focusable="true"
            android:onClick="showData" &gt;

            &lt;TextView
                android:id="@+id/code1"
                android:layout_margin="0.2dip"
                android:background="#FFFFFF"
                android:text="@string/code1" /&gt;

            &lt;TextView
                android:id="@+id/code2"
                android:layout_margin="0.2dip"
                android:background="#FFFFFF"
                android:text="@string/name1" /&gt;
        &lt;/TableRow&gt;
</code></pre>

<p>I have written onClick for second row.</p>

<p>This is onClick() in activity class:</p>

<pre><code>public void showData(View view){
        text = new EditText(this);

        //text = (EditText) findViewById(R.id.displayData);
        TextView tx1 = (TextView) findViewById(R.id.code1);
        TextView tx2 = (TextView) findViewById(R.id.code2);
        TextView tx3 = (TextView) findViewById(R.id.displayData);
        tx3 = new TextView(this);
        String str = tx1.getText().toString();
        String str1 = tx2.getText().toString();
        tx3.setText("CODE : "+str+" "+"NAME :"+str1);
        //text.setText("CODE : "+str+" "+"NAME :"+str1);
        //text.setText("NAME :"+str1);
        setContentView(tx3);
    }
</code></pre>
