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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:06:01+00:00 2026-06-04T10:06:01+00:00

Edit: The question in one line: How to pass along context from a MenuItem

  • 0

Edit: The question in one line:

How to pass along context from a MenuItem onOptionsItemSelected?

Edit 2: Here is a global indication of what I’m doing: https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/fragments/src/com/actionbarsherlock/sample/fragments/FragmentTabsPager.java


I’m building an app based on ActionBarSherlock. It uses tabs, fragments and a viewpager. It’s meant to be as versatile as possible. A tab can either contain a webview, or a listview. Here’s a screenshot:

http://dl.dropbox.com/u/11218283/Screenshot_2012-05-16-13-33-08.png

When the tab (SherlockListFragment) is first loaded, it reads content from a feed using an ASyncTask. OnPostExecute it updates the list and saves the result to a SharedPreference string (as a way of caching). As you can imagine, the AsyncTask requires context to do this. I’m calling the asynctask from the SherlockListFragment like this:

x.new refreshList(this,getActivity()).execute();

(x being a reference to my current file).

And transfer it to my AsyncTask like this

 public refreshList(TabList a,Context b){
    this.mContext = a;
    this.mCont = b;
}

All that works fine. But as you can see I’ve added in a menu item for refreshing. The way I’ve set things up, I’m not capable of re-running the ASyncTask, since I haven’t got the appropriate context information. Can anyone tell me how to perform a refresh in this situation?

If anyone willing to help requires to see more code, I’ll gladly comply.

Thanks in advance.

  • 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-04T10:06:02+00:00Added an answer on June 4, 2026 at 10:06 am

    Although Jason answered my question correctly, I found out I had an additional problem after. I placed onOptionsItemSelected in my FragmentActivity. When I moved it over inside my ListFragment I got his answer working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit 4/4/12 I STILL HAVE ONE QUESTION: I solved my issue but it adds
this is a follow up question from this one , I don't want to
Edit This question has gone through a few iterations by now, so feel free
EDIT: This question is a duplicate of What is the difference between managed and
EDIT: This question was initially too general, I think. So What I really need
-Edit- Alternative question/example How do i cast A to object to class A when
EDIT: This question is about finding definitive reference to MySQL syntax on SELECT modifying
[EDIT] This question is how do I do atomic changes to entity beans with
Edit : This question has already been asked and answered, and I apparently am
EDIT: This question is now redundant since Twitter no longer supports basic auth. I've

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.