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 ce开发者_运维技巧ll.
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);
}
});
精彩评论