如何为表格的每个单元格添加onclicklistener? [英] How can I add onclicklistener for each cell of a table?
本文介绍了如何为表格的每个单元格添加onclicklistener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有表的 TableLayout .如何为该表的每个单元格设置 onClicklisteners ?
I have a TableLayout with a table. How can I set onClicklisteners for each cell of this table?
我没有找到解决此问题的适当方法.
I have not found any proper solution for this problem.
推荐答案
尝试此代码,
TableLayout yourRootLayout = findView....
int count = yourRootLayout.getChildCount();
for(int i = 0; i < count; i++){
View v = yourRootLayout.getChildAt(i);
if(v instanceof TableRow){
TableRow row = (TableRow)v;
int rowCount = row.getChildCount();
for (int r = 0; r < rowCount; r++){
View v2 = row.getChildAt(r);
if (v2 instanceof Button){
Button b = (Button)v2;
b.setOnClickListener(this);
}
}
}
这篇关于如何为表格的每个单元格添加onclicklistener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文