Search code examples
androidandroid-studiosymbolsundefined-symbol

Cannot resolve symbol error of my variable


Here is the snippet of code. It has nothing to do with XML files. It is simply a declaration of trD, a childcount() counter. The line in error with trD is:

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

//And here is where it sits:

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);

                }
            });

I do have declaration problems at times due to my previous experience with other languages. This might be at my knowledge limit at this time. I have a previous snippet of code with trC that does work.

I have to add here that trC was necessary because childcount further down was always returning the total row count.

    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;
}

Thanks in advance. Everybody so far has been a great help.


Solution

  • I moved the trD.Childcount() outside the for loop. But this is for anybody else pursuing tablerows iwth textviews. Again, sorry for the inconvenience. Java is just a bit different than C and its variants.