Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8221485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:56:21+00:00 2026-06-07T13:56:21+00:00

I have a refresh menu item in the action bar and my main layout

  • 0

I have a refresh menu item in the action bar and my main layout just consists of a button.
so clicking on the refresh menu item should turn it into a spinner and click on the button should stop it spinning.
My problem is that when i hit on the refresh button it starts spinning which is correct but now when i rotate it it stops spinning automatically.

this is my activity.

public class MyActivity extends SherlockActivity implements OnClickListener{

View refreshView =  null;
com.actionbarsherlock.view.MenuItem refreshItem = null;
Animation rotateClockwise = null;
Button btn = null;
boolean downloadComplete = false;
boolean selected = false;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    btn = (Button)findViewById(R.id.button1);
    btn.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
    getSupportMenuInflater().inflate(R.menu.my_menu, menu);
    // Inflate our custom layout.

    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    refreshView = (View) inflater.inflate(
            R.layout.actionbar_indeterminate_progress, null);
    refreshItem = menu.findItem(R.id.menu_refresh);
    if (selected){
        refreshItem.setActionView(refreshView);
    }
    return true;
}

@Override
public boolean onOptionsItemSelected(
        final com.actionbarsherlock.view.MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_refresh:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                // Apply the View to our MenuItem
                item.setActionView(refreshView);
            }
        });
        // Refresh the data
        //refresh();
        selected =true;
        break;
    }
    return true;
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    downloadComplete = !downloadComplete;
    selected = false;
    runOnUiThread(new Runnable() {
            @Override
        public void run() {
            // TODO Auto-generated method stub
            refreshItem.setActionView(null);
        }
    });
}
}

This is my res/layout/actionbar_indeterminate_progress.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center">
    <ProgressBar android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="12dp"
        android:layout_gravity="center"
        style="?android:attr/indeterminateProgressStyle" />
</FrameLayout>

my res/layout/activity_my.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world"
        tools:context=".MyActivity" />
</RelativeLayout>

and my res/menu/my_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/menu_refresh"
        android:icon="@drawable/ic_menu_refresh"
        android:showAsAction="always"
        android:title="Refresh"/>
    <item
        android:id="@+id/settings"
        android:icon="@drawable/ic_menu_refresh"
        android:title="Settings">
    </item>
</menu>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:56:24+00:00Added an answer on June 7, 2026 at 1:56 pm

    The problem is an activity is destroyed and then created again on the orientation change. You need to do two things:

    1. Save the value of the selected field before orientation changes. Details on how to handle orientation change can be found in Handling configuration changes section and more in Handling Runtime Changes.
    2. When the activity is re-created after the orientation change, re-store selected field and use its value to start the animation if the value is true.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a menu button called Refresh that lags for a
I have a problem. I have two refresh button in differents activities that It
I have a top-level menu item which is responsible for refreshing a datagrid in
i have web page it has a page header content like main menu,logo and
I have this menu.xml <?xml version=1.0 encoding=utf-8?> <menu xmlns:android=http://schemas.android.com/apk/res/android> <item android:id=@+id/refresh android:title=Actualizar android:icon=@android:drawable/ic_menu_refresh></item> <item
I have navigation menu. When clicked, only page content div should be updated from
I am adding menu item to Application bar using this code ApplicationBar.MenuItems.Insert(0, refreshMenu); I
I have also tried .('refresh') and .page() to no avail. The text-box updates but
I have a total variable that I update with a refresh get request using
I have an updatepanel in ASP.NET that does a partial page refresh. I've had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.