如何单击 TableLayout 中的特定 TableRow [英] How to click an specific TableRow within a TableLayout

查看:22
本文介绍了如何单击 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

For more info refer Android TableRow

这篇关于如何单击 TableLayout 中的特定 TableRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆