【问题标题】:How get a table column value of a specific row in android如何在android中获取特定行的表列值
【发布时间】:2017-12-18 20:49:43
【问题描述】:

这是我在 for 循环中的代码。我有 10 个项目,但我只能选择 5 行。其余的不可点击。任何人请给我一个解决方案。

final TableRow tablerow11 = (TableRow) table.getChildAt(i);
tablerow11.setClickable(true);
final TextView sample = (TextView) tablerow11.getChildAt(0);
Log.d("finalI", String.valueOf(i));
sample.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Log.d("LOG","clicked");
    }
});

【问题讨论】:

  • 有什么问题?使用tablerow11.setEnabled(false); 禁用一行。
  • 请把你的完整代码放在这里

标签: android tablelayout


【解决方案1】:

我不确定您是否还需要答案,但这可能会有所帮助。 目前尚不清楚您是想在单击时获取表列值,还是只想循环遍历表中的所有行..

但如果是后者,这可能会有所帮助。

        //loop through table and get the Child count
        for(int i =0,j = tblSomeTable.getChildCount(); i< j ;i++)
        {
            try {
                //get Child views of the table with table.getChildAt(int index), this returns a view
                //cast it to a TextView        
                View view = tblSomeTable.getChildAt(i);
                TableRow r = (TableRow) view;
                //in this row (row i) of the table get the child element(column) where the first column would have a value of 0
                TextView getCatno = (TextView) r.getChildAt(1);
                String CatNo = getCatno.getText().toString();

这段代码基本上是逐个循环遍历表中的所有项目,然后在特定行中获取表的子视图。然后在该行中使用getChildAt,就可以得到该行的一个列值。本例获取第 i 行表中第二列的值

【讨论】:

    猜你喜欢
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 1970-01-01
    • 2017-08-22
    相关资源
    最近更新 更多