I am trying to specify a progress spinner as I have done in my testLayout.xml file, and then programmatically display and hide it as I have done in my activity code below. Whats happening however is that the progress wheel will display, but it never goes away even though I have setProgressBarVisibility(false); at the end. Any ideas? Thanks for input
layout/testLayout.xml
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/ButtonNew"
android:text="New" android:layout_alignParentBottom="true" />
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/list"
android:layout_alignParentTop="true" android:layout_above="@id/ButtonNew" />
<ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:id="@+id/progressBar1" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></ProgressBar>
</RelativeLayout>
TestActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.testLayout);
setProgressBarVisibility(true);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setProgressBarVisibility(false);
}
Well there is a problem in your code because your Thread.sleep call will cause the onCreate to wait 5 seconds before continuing. You should never perform a Thread.sleep call on the main UI thread as it will cause the application to not respond for that amount of time. Now with regards to the ProgressBar, it seems that you are not correctly using the setProgressBarVisibility with your xml file. Those functions should be used for ProgressBar’s that are contained in the title bar. You should just use findViewById(R.id.progressBar1).setVisibility(View.Gone) to hide or View.Visible to show. But if both of these calls are done inside of the onCreate you will only see the one that was called last. This is because no ui is actually shown to the user until the activity has returned from onResume and onCreate.