无法解决我的变量的符号错误

Cannot resolve symbol error of my variable

这是代码片段。它与 XML 文件无关。它只是 trD 的一个声明,一个 childcount() 计数器。 trD 错误的行是:

((TextView)((TableRow)tableC.getChildAt(trD)).getChildAt(0)).setBackgroundColor(Color.LTGRAY);

//这是它所在的位置:

try {
        for(int x=0 ; x<loopCount; x++){
            TableRow.LayoutParams params = new TableRow.LayoutParams(headerCellsWidth[x + 1], LayoutParams.MATCH_PARENT);
            params.setMargins(2, 2, 0, 0);

            //Log.d("Loadrunner", "info[x] " + x + "  " + info[x]);
            final TextView textViewB = this.bodyTextView(info[x]);
            textViewB.setTextColor(0xFF000000);
            tableRowForTableD.addView(textViewB, params);
            final int trD = tableD.getChildCount();
            //*************************************** Clickable cell
            tableRowForTableD.setClickable(true);
        }
            tableRowForTableD.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                index<tableRowForTableD.getChildCount(); ++index) {

                for (int itemPos = 0; itemPos < tableRowForTableD.getChildCount(); itemPos++) {
                        Log.d("Loadrunner", "TableD ViewGroup itemPos " + itemPos + " " + tableRowForTableD.getChildAt(itemPos).toString());
                        View view = tableRowForTableD.getChildAt(itemPos);
                        if (view instanceof TextView) {
                            TextView textView = (TextView) view;
                            textView.setBackgroundColor(Color.LTGRAY);
                            }
                }
                    ((TextView)((TableRow)tableC.getChildAt(trD)).getChildAt(0)).setBackgroundColor(Color.LTGRAY);

                }
            });

由于我以前使用其他语言的经验,我有时确实会遇到声明问题。这可能是我目前的知识限制。我之前有一段使用 trC 的代码确实有效。

我必须在这里补充一点,trC 是必要的,因为向下的 childcount 总是返回总行数。

    final TableRow tableRowForTableC = new TableRow(this.context);
    final TextView textView = this.bodyTextView(loadRecords.getItem());
    textView.setTextColor(0xFF000000);
    tableRowForTableC.addView(textView, params);
    final int trC = tableC.getChildCount();
    //*************************************** Clickable cell
    tableRowForTableC.setClickable(true);
    tableRowForTableC.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                textView.setBackgroundColor(Color.LTGRAY);

            ((TextView)((TableRow)tableD.getChildAt(trC)).getChildAt(0)).setBackgroundColor(Color.LTGRAY);
            ((TextView)((TableRow)tableD.getChildAt(trC)).getChildAt(1)).setBackgroundColor(Color.LTGRAY);
            ((TextView)((TableRow)tableD.getChildAt(trC)).getChildAt(2)).setBackgroundColor(Color.LTGRAY);
            ((TextView)((TableRow)tableD.getChildAt(trC)).getChildAt(3)).setBackgroundColor(Color.LTGRAY);
        }
    });
    tableRowForTableC.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
               Toast.makeText(getContext(), "Item row Edit", Toast.LENGTH_SHORT).show();
        return true;}
    });

    return tableRowForTableC;
}

提前致谢。到目前为止,每个人都提供了很大的帮助。

我将 trD.Childcount() 移到了 for 循环之外。但这适用于任何其他在文本视图中追求表格行的人。再次对给您带来的不便表示歉意。 Java 与 C 及其变体略有不同。