How to handle the click event in each table cell

I have a table that is as simple as this one .

I need the end user to be able to click each cell of the table and do something in each cell.

But it looks like the table layout supports a row based on the click event, no cell based on the click event. How to get rid of this?

+5
source share
2 answers

You need to handle click events using android:clickable="true"and android:onClick="clickHandlerCell"in the XML format definition file, in my case in LinearLayout.

, , view.setTag(uniqueID) . clickHandlerCell view.getTag(), .

+6

, , Table Row:

TableLayout contact_table = (TableLayout)findViewById(R.id.contact_table);
final View row=contact_table.getChildAt(i);
row.setOnClickListener(new OnClickListener(){

    @Override
    public void onClick(View v){
        // TODO Auto-generated method stub
        row_id=contact_table.indexOfChild(row);
    }
});
+2

All Articles