Android: setVisibility not setting View to visible
<p>I'm using minSDK = 8 and targetSDK = 17</p>

<p>At activity start, my 3 screens (3 different Views) are set to invisible in the XML layout. In onResume, I call setScreen(1), which starts an animation that sets View 'wait' to visible. However, at line 34 where 'wait' is set to visible, nothing happens. If I remove the comment // from line 43 where 'main' is set to invisible, 'wait' becomes visible. </p>

<p>Why does 'wait' not appear when line 43 is commented out? Why does it take setting the already invisible 'main' View to invisible for 'wait' to appear?</p>

<pre><code>public class TestActivity extends Activity {
static final String TAG = "test";
public Context context;
Activity myActivity;
UserFunctions userFunctions;
Button but_begin;
int status;
View main;
View wait;
View noconnect;
Animation fadeIntoWait;
Animation fadeIntoConnect;
Animation fadeIntoMain;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.test);
    context = getApplicationContext();
    myActivity = this;

    main = findViewById(R.id.screen_main);
    wait = findViewById(R.id.screen_wait);
    noconnect = findViewById(R.id.screen_connect);

    fadeIntoWait = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    fadeIntoConnect = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    fadeIntoMain = AnimationUtils.loadAnimation(this, R.anim.fade_in);

    fadeIntoWait.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            wait.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            //main.setVisibility(View.INVISIBLE);
            //noconnect.setVisibility(View.INVISIBLE);

        }
    });
    fadeIntoConnect.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

            noconnect.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            wait.setVisibility(View.INVISIBLE);
        }
    });
    fadeIntoMain.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

            main.setVisibility(View.VISIBLE);

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            wait.setVisibility(View.INVISIBLE);
        }
    });

}

@Override
public void onStart() {

    super.onStart();

}

@Override
public void onResume() {
    super.onResume();

    setScreen(1);

}

public void setScreen(int screen) {

    switch (screen) {
    case 1: // into wait
        wait.startAnimation(fadeIntoWait);

        break;
    case 2: // to noconnect
        noconnect.startAnimation(fadeIntoConnect);

        break;

    case 3: // to main
        main.startAnimation(fadeIntoMain);

        break;
    }
}

public void gotoActivity(Class&lt;?&gt; s) {
    Intent g = new Intent(getApplicationContext(), s);

    // Close all views before launching Dashboard
    g.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(g);
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}

public void retryConnect(View view) {

}

public void begin(View view) {
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 1, 0, "Exit App");
    menu.add(0, 2, 0, "Close Menu");
    menu.add(0, 3, 0, "Dashboard");

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case 1: // log out
        closeOptionsMenu();
        return true;
    case 2: // Exit App
        finish();
        return true;
    case 3: // Exit App
        gotoActivity(DashboardActivity.class);
        return true;

    }
    return super.onOptionsItemSelected(item);

}

public void menu(View v) {

    openOptionsMenu();

}

}
</code></pre>

<p>Here is the XML:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" &gt;

&lt;LinearLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="44dp"
    android:layout_alignParentTop="true"
    android:background="@drawable/line" &gt;
&lt;/LinearLayout&gt;

&lt;FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/header" &gt;

    &lt;RelativeLayout
        android:id="@+id/screen_wait"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000"
        android:visibility="gone" &gt;

        &lt;ImageView
            android:id="@+id/img_wait"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:contentDescription="@string/wait"
            android:src="@drawable/wait"
             /&gt;
    &lt;/RelativeLayout&gt;

    &lt;RelativeLayout
        android:id="@+id/screen_connect"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000"
        android:visibility="gone" &gt;

        &lt;ImageView
            android:id="@+id/img_connect"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:contentDescription="@string/connect"
            android:onClick="retryConnect"
            android:src="@drawable/connect"
            /&gt;
    &lt;/RelativeLayout&gt;

    &lt;RelativeLayout
        android:id="@+id/screen_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000"
        android:visibility="gone" &gt;

        &lt;ScrollView
            android:id="@+id/middle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/footer"
            android:background="#2F2430" &gt;

            &lt;RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#2F2430" &gt;

                &lt;TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" /&gt;

                &lt;TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:text="@string/idea"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#21dbd4" /&gt;

                &lt;Button
                    android:id="@+id/but_begin"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/TextView01"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="67dp"
                    android:onClick="begin"
                    android:text="Begin" /&gt;
            &lt;/RelativeLayout&gt;
        &lt;/ScrollView&gt;

        &lt;RelativeLayout
            android:id="@+id/footer"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:layout_alignParentBottom="true"
            android:background="@drawable/line"
            android:orientation="vertical" &gt;

            &lt;TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:text="Pennies:" /&gt;

            &lt;TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="22dp"
                android:layout_toRightOf="@+id/textView2" /&gt;

            &lt;Button
                android:id="@+id/btnMenu"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:onClick="menu"
                android:text="Menu" /&gt;
            &lt;/RelativeLayout&gt;
        &lt;/RelativeLayout&gt;
    &lt;/FrameLayout&gt;

&lt;/RelativeLayout&gt;
</code></pre>
