Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning a refresh ImageView into a ProgressBar

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?

like image 698
Macarse Avatar asked May 15 '26 16:05

Macarse


1 Answers

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.

like image 163
Francesco Laurita Avatar answered May 18 '26 06:05

Francesco Laurita