简体   繁体   English

android:点击TableRow的调用方法

[英]android: Call method on Click of a TableRow

I have a TableLayout in the xml that has a row. 我在xml中有一个有行的TableLayout。 I am adding more rows to the table dynamically. 我正在动态地向表中添加更多行。 How do I call a function onclick of the rows added dynamically. 如何调用动态添加的行的函数onclick。 I could do the same for the exsisting row in xml by adding android:onclick="RowClicked" and it calls RowClicked method. 我可以通过添加android:onclick =“RowClicked”为xml中的现有行做同样的事情,并调用RowClicked方法。 I want to call the same method for the dynamcally added rows to the Table. 我想为表中添加动态添加的行调用相同的方法。 How do I achieve that ? 我如何实现这一目标? I can setOnClickListener(this) and it works, but I want to call the method. 我可以setOnClickListener(this)它工作,但我想调用该方法。

If the above is not possible, then in OnClick() how can I know that the component that caused event is a TableRow. 如果无法实现上述功能,那么在OnClick()中,我怎么知道导致事件的组件是TableRow。 I mean something like view.instanceOf(TableRow) or similar can help me know that the TableRow is clicked and can handle from their. 我的意思是像view.instanceOf(TableRow)或类似的东西可以帮助我知道TableRow被点击并可以从他们处理。

Any one possiibility from the above 2 can help me resolve my problem. 上述2中的任何一个可能性都可以帮助我解决我的问题。 Any help, guidance is highly appreciated. 任何帮助,指导都非常感谢。

Thanks 谢谢

try to handle on click event of the row inside the loop where you are adding dynamic rows. 尝试处理要添加动态行的循环内的行的单击事件。 or try to set tag to each row when adding dynamic rows and on click listener use .getTag method 或者在添加动态行时尝试将标记设置到每一行,并在单击侦听器时使用.getTag方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM