title: setVisibility(View.GONE) not working for textview
body: <p>I am retrieving and displaying values from a database but all queries don't return the same number of columns so I have to hide the ones that are not required.
  java:</p>
  
  <pre><code>package com.example.testback;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  import android.app.Activity;
  import android.app.ActionBar.LayoutParams;
  import android.content.Intent;
  import android.database.Cursor;
  import android.database.SQLException;
  import android.database.sqlite.SQLiteDatabase;
  import android.os.Bundle;
  import android.view.Display;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.ArrayAdapter;
  import android.widget.LinearLayout;
  import android.widget.Spinner;
  import android.widget.TextView;
  
  public class Stations extends Activity implements OnItemSelectedListener {
  
      String lat,lng,marker;
      Spinner s1, s2;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_stations);
          // TODO Auto-generated method stub
  
          Display display =getWindowManager().getDefaultDisplay(); 
          int height = display.getHeight();
          int top=(int) (height/5.4);
          LinearLayout l=(LinearLayout)findViewById(R.id.linearL2);
          LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                     LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
          lp.setMargins(0, top,0,0);
          l.setLayoutParams(lp);
  
          s1 = (Spinner) findViewById(R.id.countries);
          s2 = (Spinner) findViewById(R.id.region);
          s1.setOnItemSelectedListener(this);
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
                  this, R.array.Countries, android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          s1.setAdapter(adapter);
  
          Bundle extras = getIntent().getExtras();
          String name= extras.getString("name");
          DataBaseHelper myDbHelper = new DataBaseHelper(
                  this.getApplicationContext());
          myDbHelper = new DataBaseHelper(this);
  
          try {
              myDbHelper.createDataBase();
          } catch (IOException ioe) {
              throw new Error("Unable to create database");
          }
  
          // Open the database
          try {
  
              myDbHelper.openDataBase();
          } catch (SQLException sqle) {
              sqle.printStackTrace();
          }
  
          // Get the readable version
          SQLiteDatabase db = myDbHelper.getReadableDatabase();
          Cursor cur;
          cur = db.rawQuery("SELECT * FROM REGIONS WHERE _id='"+name+"';", null);
          int i = 0;
          cur.moveToFirst();
          TextView v=(TextView)findViewById(R.id.address);
          v.setText(cur.getString(1));
          int index;
  
          index=cur.getColumnIndex("ph1");
          if(index!=-1){
              v=(TextView)findViewById(R.id.ph1);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
              v=(TextView)findViewById(R.id.tit_ph1);
              v.setVisibility(View.VISIBLE);
          } else{
              v=(TextView)findViewById(R.id.ph1);
              v.setVisibility(View.GONE);
              v=(TextView)findViewById(R.id.tit_ph1);
              v.setVisibility(View.GONE);
          }
  
          index=cur.getColumnIndex("ph2");
          if(index!=-1){
              v=(TextView)findViewById(R.id.ph2);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
              v=(TextView)findViewById(R.id.tit_ph2);
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.ph2);
              v.setVisibility(View.GONE);  
              v=(TextView)findViewById(R.id.tit_ph2);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("fax");
          if(index!=-1){
              v=(TextView)findViewById(R.id.fax);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
              v=(TextView)findViewById(R.id.tit_fax);
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.fax);
              v.setVisibility(View.GONE); 
              v=(TextView)findViewById(R.id.tit_fax);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("email1");
          if(index!=-1){
              v=(TextView)findViewById(R.id.email1);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.email1);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("email2");
          if(index!=-1){
              v=(TextView)findViewById(R.id.email2);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.email2);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("dom_ph1");
          if(index!=-1){
              v=(TextView)findViewById(R.id.dom_ph1);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.dom_ph1);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("dom_ph2");
          if(index!=-1){
              v=(TextView)findViewById(R.id.dom_ph2);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.dom_ph2);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("dom_fax");
          if(index!=-1){
              v=(TextView)findViewById(R.id.dom_fax);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.dom_fax);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("dom_email1");
          if(index!=-1){
              v=(TextView)findViewById(R.id.dom_email1);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.dom_email1);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("dom_email2");
          if(index!=-1){
              v=(TextView)findViewById(R.id.dom_email2);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.dom_email2);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("int_ph1");
          if(index!=-1){
              v=(TextView)findViewById(R.id.int_ph1);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.int_ph1);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("int_ph2");
          if(index!=-1){
              v=(TextView)findViewById(R.id.int_ph2);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.int_ph2);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("int_fax");
          if(index!=-1){
              v=(TextView)findViewById(R.id.int_fax);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.int_fax);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("int_email1");
          if(index!=-1){
              v=(TextView)findViewById(R.id.int_email1);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.int_email1);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("int_email2");
          if(index!=-1){
              v=(TextView)findViewById(R.id.int_email2);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.int_email2);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("cargo_ph1");
          if(index!=-1){
              v=(TextView)findViewById(R.id.cargo_ph1);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.cargo_ph1);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("cargo_ph2");
          if(index!=-1){
              v=(TextView)findViewById(R.id.cargo_ph2);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.cargo_ph2);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("cargo_fax");
          if(index!=-1){
              v=(TextView)findViewById(R.id.cargo_fax);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.cargo_fax);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("cargo_email1");
          if(index!=-1){
              v=(TextView)findViewById(R.id.cargo_email1);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.cargo_email1);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndex("cargo_email2");
          if(index!=-1){
              v=(TextView)findViewById(R.id.cargo_email2);
              v.setText(cur.getString(index));
              v.setVisibility(View.VISIBLE);
          }else{
              v=(TextView)findViewById(R.id.cargo_email2);
              v.setVisibility(View.GONE);  
          }
  
          index=cur.getColumnIndexOrThrow("loc_lat");
          lat=cur.getString(index);
          index=cur.getColumnIndexOrThrow("loc_long");
          lng=cur.getString(index);
          index=cur.getColumnIndexOrThrow("marker");
          marker=cur.getString(index);
          /*while (cur.isAfterLast() == false) {
              //list.add(cur.getString(0));
              cur.moveToNext();
          }*/
  
          cur.moveToPosition(0);
  
          // Close
          myDbHelper.close();
      }
      public void go(View view){
          Intent i = new Intent(Stations.this, Map.class);
          i.putExtra("lat",lat);
          i.putExtra("long",lng);
          i.putExtra("marker",marker);
          startActivity(i);
          finish();
      }
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
              long arg3) {
          // TODO Auto-generated method stub
          List&lt;String&gt; list = new ArrayList&lt;String&gt;();
          if (s1.getSelectedItem().equals("India")) {
              list.add("Select Station");
              DataBaseHelper myDbHelper = new DataBaseHelper(
                      this.getApplicationContext());
              myDbHelper = new DataBaseHelper(this);
  
              try {
                  myDbHelper.createDataBase();
              } catch (IOException ioe) {
                  throw new Error("Unable to create database");
              }
  
              // Open the database
              try {
  
                  myDbHelper.openDataBase();
              } catch (SQLException sqle) {
                  sqle.printStackTrace();
              }
  
              // Get the readable version
              SQLiteDatabase db = myDbHelper.getReadableDatabase();
              Cursor cur;
              cur = db.rawQuery("SELECT * FROM REGIONS ORDER BY _id ASC;", null);
              int i = 0;
              cur.moveToFirst();
              while (cur.isAfterLast() == false) {
                  list.add(cur.getString(0));
                  cur.moveToNext();
              }
  
              cur.moveToPosition(0);
  
              // Close
              myDbHelper.close();
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_spinner_item, list);
              dataAdapter
                      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              s2.setAdapter(dataAdapter);
          } else if (s1.getSelectedItem().equals("SAARC Countries")) {
              list.add("Select Station");
              list.add("Chittagong");
              list.add("Colombo");
              list.add("Dhaka");
              list.add("Kabul");
              list.add("Kathmandu");
              list.add("Male");
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_spinner_item, list);
              dataAdapter
                      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              s2.setAdapter(dataAdapter);
          } else if (s1.getSelectedItem().equals("Russia")) {
              list.add("Moscow");
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_spinner_item, list);
              dataAdapter
                      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              s2.setAdapter(dataAdapter);
          } else if (s1.getSelectedItem().equals("USA and Canada")) {
              list.add("Select Station");
  
              list.add("Chicago");
              list.add("Los Angeles");
              list.add("New York");
              list.add("Toronto");
              list.add("Washington DC");
              list.add("Newark Airport (EWR)");
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_spinner_item, list);
              dataAdapter
                      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              s2.setAdapter(dataAdapter);
          } else if (s1.getSelectedItem().equals("Southeast Asia, Australia")) {
              list.add("Select Station");
              list.add("Bangkok");
              list.add("Hongkong");
              list.add("Jatarka");
              list.add("Melbourne");
              list.add("Sydney");
              list.add("Yangon");
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_spinner_item, list);
              dataAdapter
                      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              s2.setAdapter(dataAdapter);
          } else if (s1.getSelectedItem().equals("Gulf and Middle East")) {
              list.add("Select Station");
              list.add("Bahrain");
              list.add("Beirut");
              list.add("Cairo");
              list.add("Dubai");
              list.add("Muscat");
              list.add("Tehran");
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_spinner_item, list);
              dataAdapter
                      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              s2.setAdapter(dataAdapter);
          }
  
          else if (s1.getSelectedItem().equals("UK and Europe")) {
              list.add("Select Station");
  
              list.add("Amsterdam");
              list.add("Frankfurt");
              list.add("London");
              list.add("Madrid");
              list.add("Zurich");
              list.add("Paris");
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_spinner_item, list);
              dataAdapter
                      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              s2.setAdapter(dataAdapter);
          } else if (s1.getSelectedItem().equals("Far East")) {
              list.add("Select Station");
  
              list.add("Osaka");
              list.add("Seoul");
              list.add("Tokyo");
              ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this,
                      android.R.layout.simple_spinner_item, list);
              dataAdapter
                      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              s2.setAdapter(dataAdapter);
          }
          s2.setOnItemSelectedListener(new OnItemSelectedListener() {
  
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                      int arg2, long arg3) {
                  if (s2.getSelectedItem().toString() != "Select Station") {
                      String s = s2.getSelectedItem().toString();
                      Intent i = new Intent(Stations.this, Stations.class);
                      i.putExtra("name", s);
                      startActivity(i);
                  }
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
              }
          });
      }
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>
  
  <p>The xml for that element is:</p>
  
  <pre><code>&lt;LinearLayout
      android:id="@+id/linearLayout4"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal" &gt;
  
          &lt;TextView
              android:id="@+id/tit_fax"
              android:layout_width="0dip"
              android:layout_height="wrap_content"
              android:layout_weight=".4"
              android:text="FAX"
              android:visibility="visible"
              android:textSize="14dp" /&gt;
  
          &lt;TextView
              android:id="@+id/fax"
              android:layout_width="0dip"
              android:layout_height="wrap_content"
              android:layout_weight=".6"
              android:visibility="visible"
              android:text=" " /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>But it is still visible when it should have been gone</p>