【问题标题】:Cannot resolve symbol error of my variable无法解决我的变量的符号错误
【发布时间】:2016-12-25 19:07:47
【问题描述】:

这里是sn-p的代码。它与 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 的 sn-p 代码,它确实有效。

我必须在此处添加 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 循环之外,因为我可以在那里读取增量。我是一个开发者,必须通过公告程序来实现我想要实现的目标。我在真空中工作太多了。拉尼曼精神禁锢。

标签: android android-studio symbols undefined-symbol


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2013-09-26
    • 2015-09-05
    • 1970-01-01
    • 2012-07-10
    • 2016-05-25
    相关资源
    最近更新 更多