Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem when moving TableRow within TableLayout
    primarykey
    data
    text
    <p>I am trying to dynmically move several rows around at once within a specific view based on user input.</p> <p>The use-case is that the user picks an option and based on the option, certain rows are show/hidden and the rows need to be rearranged to make sense to the user.</p> <p>The <code>TableLayout</code> is instantiated in <code>XML</code>, but the <code>TableRow</code> and it's layout(s) are instantiated in code. I have tried several different methods, with varying levels of success.</p> <p>Code which works for hiding/disabling properly:</p> <pre><code>private void updateTimeRow(TargetType goalTarget) { TableRow timeRow = (TableRow)this.findViewById(timeId + 100); EditText timeText = (EditText)this.findViewById(timeId); if (goalTarget == TargetType.daysRowedWeek || goalTarget == TargetType.metersDay || goalTarget == TargetType.metersSeason || goalTarget == TargetType.metersWeek) { timeRow.setVisibility(View.GONE); timeRow.setEnabled(false); timeText.setEnabled(false); } else if (goalTarget == TargetType.splitForDistance || goalTarget == TargetType.unknown) { setTimeText(currentTarget.recalcTime().toString()); timeRow.setVisibility(View.VISIBLE); timeRow.setEnabled(false); timeText.setEnabled(false); } else { timeRow.setVisibility(View.VISIBLE); timeRow.setEnabled(true); timeText.setEnabled(true); } } </code></pre> <p>Based on questions answered here, I tried removing/re-adding rows, with this piece of code:</p> <pre><code> int rowNum = -1; tableLayout.removeView(timeRow); switch (goalTarget) { case unknown: case timeForDistance: rowNum = 2; break; case splitForDistance: rowNum = 4; break; case splitForTime: rowNum = 3; break; } tableLayout.addView(timeRow, rowNum); </code></pre> <p>Two things break here:</p> <ul> <li>The disable code fails (whether this code is run before of after the enable/disable code above</li> <li>The rows in my layout get all screwed up.</li> </ul> <p>So, how do I move the rows around dynamically, while properly hiding/showing/enabling/disabling the different rows?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload