Turning a refresh ImageView into a ProgressBar

android, progress-bar

Solution

You could add the progress bar view into the `RelativeLayout` which overlaps the `ImageView` with `visibility:gone` and then play with `setVisibilty(View.VISIBILE)`/`setVisibilty(View.GONE)` on your `ImageView` and `ProgressBar`.

Maybe a `ViewSwitcher` could help you too.

Problem

I am doing a custom title for my android app and I want to have a refresh button like the Twitter app. I am using a `RelativeLayout` an my ImageView is defined by: ``` <ImageView android:id="@+id/title_refresh" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_menu_refresh" android:layout_alignParentRight="true"> </ImageView> ``` In my `Activity` I have something like this: ``` refreshView = (ImageView) findViewById(R.id.title_refresh); refreshView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { /* Make the refreshView turn into a progress bar. */ startService(new Intent(MyActivity.this, MyService.class)); } } ``` I would like the ImageView to turn into a ProgressBar while I wait for my service to finish processing. How is the correct way to do this?

Original source