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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:43:15+00:00 2026-05-29T09:43:15+00:00

In my projects I kept different images for categories . When I click on

  • 0

In my projects I kept different images for categories. When I click on each category image I am passing its category id to other page statically and setting the drawable image of that category in the new page.

My Code:

Firstpage.java

public static String categoryid;

category1.setOnClickListener(new View.OnClickListener()
{
   public void onClick(View view)
    {
     categoryid="0";
     Intent myIntent = new Intent(view.getContext(),Nextpage.class);
     startActivityForResult(myIntent, 0);
    }
});
category2.setOnClickListener(new View.OnClickListener()
{
   public void onClick(View view)
   {
    categoryid="1";
    Intent myIntent = new Intent(view.getContext(),Nextpage.class);
    startActivityForResult(myIntent, 0);
   }
});
category3.setOnClickListener(new View.OnClickListener()
{
   public void onClick(View view)
   {
    categoryid="2";
    Intent myIntent = new Intent(view.getContext(),Nextpage.class);
    startActivityForResult(myIntent, 0);
   }
});

Nextpage.java

public static String catid = Firstpage.categoryid;
          ImageView categorytype=(ImageView)findViewById(R.id.imageView1);

             if(catid=="0")
            { 
                categorytype.setBackgroundResource(R.drawable.image1);
            }

             else if(catid=="1")
            { 
                categorytype.setBackgroundResource(R.drawable.image2);
            }
           else  if(catid=="2")
            {
                   categorytype.setBackgroundResource(R.drawable.image3);
            }

First time when I am clicking on the category image it is passing the category id to the next page and that particular image is setting in the nextpage. After that I clicked the back button(android back button) and went to Firstpage.java and again clicked on other image. But this time also the same image stored. The category id didnt changed. The category id is not refreshing…How to refresh the category id? Any suggestion will be thankful…..

  • 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-29T09:43:15+00:00Added an answer on May 29, 2026 at 9:43 am

    Don’t use static variables for this. Pass the category ID to your Nextpage activity through the intent. In Firstpage.java:

    public static final String CATEGORY_KEY = "category";
    
    category1.setOnClickListener(new View.OnClickListener()
    {
       public void onClick(View view)
        {
         Intent myIntent = new Intent(this,Nextpage.class);
         myIntent.putExtra(CATEGORY_KEY, "0");
         startActivityForResult(myIntent, 0);
        }
    });
    

    Then retrieve it in the onCreate(Bundle) method of Nextpage.java:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        String categoryid = intent.getStringExtra(Firstpage.CATEGORY_KEY);
        . . .
    }
    

    The reason your method doesn’t work is that Nextpage.catid is initialized when the class is loaded, but the assignment statement is not executed again unless the class is unloaded and needs to be reloaded.

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

Sidebar

Related Questions

I have multiple projects in a couple of different workspaces. However, it seems like
I have recently upgraded to Visual Studio 2010. I have kept database projects separate
In our git-svn managed project, we have 3 upstream projects that are all kept
I have not used any OO in the past in projects, as I kept
When trying to launch and run a flex/java project in eclipse I kept getting
Projects have many tasks and a task has a custom RESTful action called 'approve'.
Some projects have properties have miscellaneous settings such as: AllowPayments, ShowSideBar, SectionTitle. Really things
Our projects are using objects as the data source to reports. Our business layer
Our projects are typically stored as single projects, and are not part of a
C++ projects have a linker option to embed manifest to require UAC elevation (/MANIFESTUAC:level)

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.