Xaloju Xaloju - 3 months ago 7
Android Question

Why some TableLayout rows are not becoming invisible?

Depending on the

Spinner
selection, my replaced table should change to invisible, but if it's larger than the new table some old rows still being shown. When I select again the same option it disappears properly.

Example CODE

Spinner s;
s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// your code here
textSpinner = s.getSelectedItem().toString();
switch (position){
case 0:
tableLayout2.setVisibility(View.INVISIBLE);
tableLayout1.setVisibility(View.VISIBLE);
break;
case 1:
tableLayout1.setVisibility(View.INVISIBLE);
tableLayout2.setVisibility(View.VISIBLE);
break;
}
}

Answer

Use View.GONE instead of View.INVISIBLE:

switch (position){
    case 0:
        tableLayout2.setVisibility(View.GONE);
        tableLayout1.setVisibility(View.VISIBLE);
        break;
    case 1:
        tableLayout1.setVisibility(View.GONE);
        tableLayout2.setVisibility(View.VISIBLE);
        break;
}