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?
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.
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);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With