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 8870713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:48:14+00:00 2026-06-14T17:48:14+00:00

I have a Refresh button that I would like to make visible depending on

  • 0

I have a Refresh button that I would like to make visible depending on the situation.

When the Refresh button is clicked I can make it invisible without a problem, however, I cannot make it visible again once the AsyncTask process finishes. I have trouble passing the MenuItem value back to the AsyncTask.

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getSupportMenuInflater().inflate(R.menu.refresh_action_provider, menu);        
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch(item.getItemId()) {
  case R.id.menu_refresh:
      item.setVisible(false); //hide refresh button
      setSupportProgressBarIndeterminateVisibility(true);
    Toast.makeText(getApplicationContext(), "REFRESH CLiCKED", Toast.LENGTH_SHORT).show();
    new DownloadNewsTask().execute(); 
    return true;
  }
  return false;
}
  • 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-14T17:48:19+00:00Added an answer on June 14, 2026 at 5:48 pm

    You could pass your item in your task’s constructor, store it and make it visible in onPostExecute method:

    public class DownloadNewsTask extends AsyncTask<...> {
    
        private final MenuItem item;
    
        public DownloadNewsTask(MenuItem item) {
            this.item = item;
        }
    
        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            item.setVisible(true);
        }
    
        ...
    }
    

    And then:

    new DownloadNewsTask(item).execute(); 
    

    You can also have the item be a member of your activity class and access it from your task if it is defined as an inner class of your activity:

    public class TestActivity extends Activity {
    
    protected MenuItem refreshItem;
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getSupportMenuInflater().inflate(R.menu.refresh_action_provider, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.menu_refresh:
            this.refreshItem = item;
            item.setVisible(false); // hide refresh button
            setSupportProgressBarIndeterminateVisibility(true);
            Toast.makeText(getApplicationContext(), "REFRESH CLiCKED", Toast.LENGTH_SHORT).show();
            new DownloadNewsTask().execute();
            return true;
        }
        return false;
    }
    
    public class DownloadNewsTask extends AsyncTask<Void, Void, Void> {
    
        @Override
        protected Void doInBackground(Void... params) {
            // your stuff...
        }
    
        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            refreshItem.setVisible(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. I have two refresh button in differents activities that It
Anyone have some sample code for an in-app browser that they would like to
I have an index.php file that I would like to run getdata.php every 5
I have a set of pages that I would like to ask the user
I have a submit button on top that's normally doing a partial refresh of
I would like to use the jQuery button elements as standalone - without the
I would like to know how I can only refresh a specific element in
I have a page containing a PrimeFaces (2.2.1) Editor component, a Refresh button and
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.