Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle click event on each cell of a table layout

I have a table layout which is as simple as this one.

What I need is to allowed end user to click each cell of the table, and do something on each cell.

But, it seems android table layout only support row based on click event, no cell based on click event. How to get rid of this?

like image 303
Leem Avatar asked Jul 05 '11 08:07

Leem


2 Answers

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

To identify wich cell was clicked you could tag the view of each cell using view.setTag(uniqueID) when you create it. In clickHandlerCell function use view.getTag() to get the identity of your cell.

like image 100
crubio Avatar answered Oct 23 '22 16:10

crubio


Try this code for click in particular 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);
    }
});
like image 20
Venky Avatar answered Oct 23 '22 16:10

Venky