79288579

Date: 2024-12-17 16:11:09
Score: 0.5
Natty:
Report link

The issue with accessing the hidden column in your TableLayout is because setting the android:visibility attribute of the TextView to invisible doesn't remove it from the layout hierarchy While the view becomes invisible, it still occupies its position in the TableRow.

Here's why you can't access the hidden column using getChildAt(0):

Index Order: getChildAt(0) retrieves the first visible child of the TableRow. Since the first TextView is invisible, the second TextView (with the name) becomes the first visible child with an index of 0.

u can

  1. Maintain Child Order, that is instead of relying on the index, iterate through all children of the TableRow:

    val tableRow = stableLayout.getChildAt(0) as TableRow for (i in 0 until tableRow.childCount) { val child = tableRow.getChildAt(i) if (child.id == R.id.idautoint) { val hiddenValue = (child as TextView).text.toString() break } }

  2. Use a Custom Layout:

Create a custom layout (e.g., a LinearLayout) that holds the three TextViews, with the hidden one positioned first. Add this custom layout to the TableRow instead of individual TextViews. This way, the hidden TextView remains at index 0 within its parent custom layout, and you can access it using getChildAt(0) on the custom layout.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Accolade