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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:01:47+00:00 2026-05-31T22:01:47+00:00

I have a class called HeaderView which I use all over my application: public

  • 0

I have a class called HeaderView which I use all over my application:

public HeaderView(Context context, AttributeSet attrs) {
    super(context, attrs);
    ctx = context;

    commonApi = AAALifestyleApplication.commonApi;
    user = commonApi.getCurrentUser();

    inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.header_view, this, true);

    ((ImageView)this.findViewById(R.id.logo)).setOnClickListener(this);

    inboxButton = (ImageView) this.findViewById(R.id.inbox_image);
    inboxButton.setOnClickListener(this);
    inboxButton2 = (ImageView) this.findViewById(R.id.inbox_image2);
    inboxButton2.setOnClickListener(this);

    requestsButton = (ImageView) this.findViewById(R.id.requests_image);
    requestsButton.setOnClickListener(this);
    requestsButton2 = (ImageView) this.findViewById(R.id.requests_image2);
    requestsButton2.setOnClickListener(this);

    progressBar = (ProgressBar) this.findViewById(R.id.header_progress_bar);
    if (!showProgressBar) {
        progressBar.setVisibility(INVISIBLE);
    }
    AAAAsyncTask.setProgressBarListener(this);

    refreshView();
}

public static void refreshView(){
    SharedPreferences sp = ctx.getSharedPreferences("HeaderView", Context.MODE_PRIVATE);
    int newMessages = sp.getInt("newMessagesCount", 0);
    int newRequests = sp.getInt("newRequestsCount", 0);
    if(newMessages > 0){
        Log.d("daim", "new messages!");
        inboxButton.setVisibility(View.GONE);
        inboxButton2.setVisibility(View.VISIBLE);
    }
    else{
        Log.d("daim", "no new messages!");
        inboxButton.setVisibility(View.VISIBLE);
        inboxButton2.setVisibility(View.GONE);
    }
    if(newRequests > 0){
        requestsButton.setVisibility(View.GONE);
        requestsButton2.setVisibility(View.VISIBLE);
    }
    else{
        requestsButton.setVisibility(View.VISIBLE);
        requestsButton2.setVisibility(View.GONE);
    }
}

In my Activity, this HeaderView gets called onCreate cause its specified in the XML, and also in onResume() like this:

@Override
public void onResume(){
    super.onResume();
    HeaderView.refreshView();
}

In the onCreate() method this works correctly, but onResume() I get the right amount of messages and I even logged this, so I know for sure that “no new messages” is printed, but the setVisibility() method doesn’t update at all, and instead I see the previous ImageView when I had “new messages”.

Please help, I’ve tried using handler with a thread to see if that was the problem, but it still remains this way.

  • 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-05-31T22:01:48+00:00Added an answer on May 31, 2026 at 10:01 pm

    You should instantiate your view, and make the refreshView non-static.

    Declare your Activity like this:

    public class YourActivity extends Activity {
        private HeaderView mHeaderView;
    
        @Override
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            mHeaderView = new HeaderView(this);
        }
    
        @Override
        public void onResume(){
            super.onResume();
            mHeaderView.refreshView();
        }
    }
    

    And remove the static keyword in your refreshView method declaration.

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

Sidebar

Related Questions

I have a class called MODEL in which public static int theMaxFrames resides. The
I have a class called EventConsumer which defines an event EventConsumed and a method
I have this class called Table: class Table { public string Name { get
I have a class called User with static function loginRequired(), which returns false if
I have a class called Book; class Book { public string Name { get;
I have a class called Path for which there are defined about 10 methods,
I have a class called Object which stores some data. I would like to
I have a class called PurchaseOrderItem public class PurchaseOrderItem { public Int64 PONumber {
I have a class of buttons called Keys.java which returns a panel of buttons
I have a class called GestorePersonale which holds a list of instances of another

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.