如何点击一个TableLayout内的特定的TableRow [英] How to click an specific TableRow within a TableLayout
本文介绍了如何点击一个TableLayout内的特定的TableRow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做我自己的复合控件显示使用TableLayout,并根据对象的数组,即时通讯结合了它,现在我想为了选择具有其特定数据的特定行循环中添加编程Tablerows数据网格所使用的方法。那么,如何选择一个特定的行获取其数据委托的方法?
I made my own compound control that display a data grid using TableLayout and adding programmatically Tablerows within a loop depending of the Array of Object that im binding to it and now i want to select an specific row with its specific data in order to be used by a method. So how can i select an specific row retrieving its data to delegate a method?
推荐答案
您好,你可以尝试这样的事情,
hi you can try something like this,
// create a new TableRow
TableRow row = new TableRow(this);
row.setClickable(true); //allows you to select a specific row
row.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
v.setBackgroundColor(Color.GRAY);
System.out.println("Row clicked: " + v.getId());
//get the data you need
TableRow tablerow = (TableRow)v.getParent();
TextView sample = (TextView) tablerow.getChildAt(2);
String result=sample.getText().toString();
}
});
有关详细信息请参阅的Android的TableRow
这篇关于如何点击一个TableLayout内的特定的TableRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文