Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show Indeterminate Progress bar when Refresh button is pressed in ActionBarSherlock?

How to show Indeterminate ProgressBar when Refresh button is pressed in ActionBarSherlock and again show Refresh Button when ViewGroup on refreshed?

Update 1: I have a answer here which is incomplete. I am placing a bounty on question so that more developers can help build a good answer which can useful to others in future.

How can we show a Indeterminate ProgressBar which looks like the one shown in the image belowenter image description here

like image 579
Gaurav Agarwal Avatar asked Jun 05 '12 21:06

Gaurav Agarwal


People also ask

What is indeterminate progress bar?

Indeterminate mode is the default for progress bar and shows a cyclic animation without a specific amount of progress indicated. The following example shows an indeterminate progress bar: <ProgressBar android:id="@+id/indeterminateBar" android:layout_width="wrap_content" android:layout_height="wrap_content" />

How do I stop indeterminate progress bar?

You can set your progressbar's visibility to invisible or gone through progressbar. setVisibility(View. INVISIBLE); or progressBar.


1 Answers

It seems like ActionBarSherlock doesn't provide specific method to animate a refresh MenuItem.

What you can do (by using classic android API) is to use the setActionView(int resId) method and give the id of a layout with a ProgressBar in it.

At the beginning of your refresh action just call :

item.setActionView(R.layout.refresh_menuitem);

And when your refresh action is finished call :

item.setActionView(null);

Here is a sample of what your layout file refresh_menuitem.xml can have :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:addStatesFromChildren="true"
              android:focusable="true"
              android:paddingLeft="4dp"
              android:paddingRight="4dp"
              android:gravity="center"
              style="?attr/actionButtonStyle">
    <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="true"
            style="@android:style/Widget.ProgressBar.Small"/>
</LinearLayout> 
like image 78
gurvanhenry Avatar answered Nov 13 '22 00:11

gurvanhenry