Android ProgressBar

We can show ProgressBar while downloading image/video/getting response from server etc.

Steps are given below:

In main.xml write following code.

[sourcecode language=”xml”]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black">
<LinearLayout android:id="@+id/layout_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:visibility="gone">
<ProgressBar android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyle"/>
<TextView android:id="@+id/label_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="Loading"/>
</LinearLayout>
<RelativeLayout android:id="@+id/myLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

</RelativeLayout>
</RelativeLayout>
[/sourcecode]

where layout_loading will http://cheapcialiswww.com show ProgressBar, and after you get expected response, you can disable ProgressBar by calling disableSpinner() and show

your own layout (myLayout).

Note the style of ProgressBar i.e. style="?android:attr/progressBarStyle"

There are three more attributes that you can apply to a ProgressBar’s style, such as:
1) style="?android:attr/progressBarStyleSmall"

style="?android:attr/progressBarStyleSmall"

2) style="?android:attr/progressBarStyleLarge"

style="?android:attr/progressBarStyleLarge"

3) style="?android:attr/progressBarStyleHorizontal" is typical incremental ProgressBar.

style="?android:attr/progressBarStyleHorizontal"

i.e Write following code in activity:

Enable Spinner:

[sourcecode language=”java”]
private void enableSpinner() {
findViewById(R.id.layout_loading).setVisibility(View.VISIBLE);
findViewById(R.id.myLayout).setVisibility(View.GONE);
}
[/sourcecode]

Disable Spinner:

[sourcecode language=”java”]
private void disableSpinner() {
findViewById(R.id.layout_loading).setVisibility(View.GONE);
findViewById(R.id.myLayout).setVisibility(View.VISIBLE);
}
[/sourcecode]