Android: hide / show table rows

Roman picture Roman · Mar 2, 2015 · Viewed 7k times · Source

I have a table layout (a form with real estate filtering parameters). I need to hide/show rows with filtering parameters when user selects realty type from Spinner list (apartment, house, land etc.). Is it possible? Is TableLayout good for that or would it be better to use LinearLayout? When it's better to use TableLayout over LinearLayout? I have a simple table with horizontal form which looks like this:

-------------------------
field name: [input field]
-------------------------
field name: [input field]
-------------------------

I already found that I can remove / add rows:

tableLayout.addView(row);
tableLayout.removeView(row);

Is it the only one way to go? Can I just hide/show rows without removing them?

Answer

David M picture David M · Mar 2, 2015

You can use <variable>.setVisible(View.GONE) and <variable>.setVisible(View.VISIBLE) to hide and show a tableRow variable. There will be no need to reposition the row(s).

Good luck!