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

  • Home
  • SEARCH
  • 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 7678939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:45:41+00:00 2026-05-31T17:45:41+00:00

hey I’m creating an app with two switches on it that change the background

  • 0

hey I’m creating an app with two switches on it that change the background of the xml.

however, if the user touches button 1 then 2 I want it to change the background from pic1 to pic2(on first button hit) then pic4(on second button hit)

but if the user touches button 2 then 1 I want it to change the background from pic1 to pic3(on first button hit) then pic4(on second button hit)

at the moment this is my script;

package com.jamie.game;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class level2 extends Activity implements OnClickListener{

    Button button1;
    View targetView;
    Button button2;

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.level2);
    targetView = (View)findViewById(R.id.level2);
    button1 = (Button) findViewById(R.id.button1);
    button1.setVisibility(View.VISIBLE);
    button1.setBackgroundColor(Color.TRANSPARENT);
    button1.setOnClickListener((android.view.View.OnClickListener)this);
    button2 = (Button) findViewById(R.id.button2);
    button2.setVisibility(View.VISIBLE);
    button2.setBackgroundColor(Color.TRANSPARENT);
    button2.setOnClickListener((android.view.View.OnClickListener)this);
    }

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    if(v.getId()==(R.id.button1)){
            targetView.setBackgroundResource(R.drawable.pic2);
            if(v.getId()==(R.id.button2)){
            targetView.setBackgroundResource(R.drawable.pic4);
    }else
        if(v.getId()==(R.id.button2)){
                targetView.setBackgroundResource(R.drawable.pic3);
            if(v.getId()==(R.id.button2)){
            targetView.setBackgroundResource(R.drawable.pic4);

        }
    }


} 

but all this does is alternate between pic2 and pic3 on button clicks

  • 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-31T17:45:42+00:00Added an answer on May 31, 2026 at 5:45 pm

    Probably you need to create a variable to store the ID of the button that was just clicked. Then, when you receive the next click, you can just check this variable to know if the sequence matches your condition. For example, if you click the first button – store its ID in an int lastChecked variable, then when you click the second button – you should whether lastChecked equals to the first button ID. If it is – then you can run your View changing code. Hope this helps.

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

Sidebar

Related Questions

Hey I'm building an app that will allow a user to log into a
Hey all i have two JFrames one is my main login frame, user enters
Hey all i have an XML file that i am trying to loop though.
Hey I am looking to change my a plugin that I created to use
Hey I thought about writing a function that prompts me in certain situations (perl
Hey everyone I have a basic search function here that allows me to search
Hey I can't figure out an error I got. I had my App working
Hey i am new to iOS development, in my app i want to fetch
Hey can we hide/show tab layout on button click which will be placed below
hey i got a contnet type that i made and i want to twweak

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.