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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:29:42+00:00 2026-05-28T04:29:42+00:00

Hey so I’ve been searching around for this topic and couldn’t find a whole

  • 0

Hey so I’ve been searching around for this topic and couldn’t find a whole lot so I think I’m in the clear to ask this. What I want to accomplish is have two image buttons that are overlapping in an XML layout. Then in the .java file when the top button is clicked it dissapears and the second image button appears. When that is clicked it dissapears and the first image button reappears and on and on.

The problem I’m having is when i click the first button it dissapears fine and works for a total of two times around then everything dissapears. I’m not sure if I’m doing this right and there might be a better way to accomplish this than how i’m doing it so I will happily take advice.

Also, the reason i don’t have another line in the fist button that sets musicbutton2 as visible is because when I do that the label highlights in blue and it causes a force close.

optionsActivity.java (New):

    package com.crazycastles;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;

public class optionsActivity extends Activity {
    /** Called when the activity is first created. */
    ImageButton musicbutton, musicbutton2;
    boolean answer=true;
    final MediaPlayer buttonSound = MediaPlayer.create(
            optionsActivity.this, R.raw.swords);


    @Override

        public void onCreate(Bundle savedInstanceState) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

            super.onCreate(savedInstanceState);
            setContentView(R.layout.options);




          if (answer=true){  
            //CREATE BUTTON 1 & SOUND
            final ImageButton musicbutton = (ImageButton) findViewById(R.id.musicbutton);
            musicbutton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                musicbutton.setBackgroundResource(R.drawable.musicbutton2);
                buttonSound.start();
                answer=false;
            }
            });
          }


          if (answer!=true){  
                //CREATE BUTTON 1 & SOUND
                final ImageButton musicbutton = (ImageButton) findViewById(R.id.musicbutton);
                musicbutton.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                    musicbutton.setBackgroundResource(R.drawable.musicbutton);
                    buttonSound.start();
                    answer=true;
                }
                });
              }




}
}

options.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/mainscreen" >

     <ImageButton
        android:id="@+id/musicbutton"
        android:layout_width="218dp"
        android:layout_height="51dp"
        android:layout_marginBottom="100dp"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="200dp"
        android:background="@drawable/musicbutton"
        android:scaleType="centerCrop"
          />



</LinearLayout>
  • 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-28T04:29:43+00:00Added an answer on May 28, 2026 at 4:29 am

    I think your problems are coming because of the way you are trying to use the linear layout and the margin top to scoot one of the buttons up.

    Check out RelativeLayout if you switch to using one of those as your parent then you can get rid of the margin stuff. The buttons will default to being overlapped like you are aiming for. If you do that and are still getting the same problem then add some Log debugging statments to your click listeners that output when the buttons are changing visibility to try to see what is happening.

    If your aim is simply to make the way the button looks change I would recommend only using one button and just changing its background with Button.setBackgroundResource(). You can just keep a boolean flag and use it check whether you should set to R.drawable.musicbutton or R.drawable.musicbutton2

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

Sidebar

Related Questions

Hey am just curious to know if this can be done! I want to
Hey, I've been developing an application in the windows console with Java, and want
Hey all, I want to change a value in a table (in a mysql
Hey, I want to store application configuration data. Currently, I'm using INIs but they
Hey I am getting this error: error: conversion to non-scalar type requested Here are
hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey all I want to reseed my IDENTITY COLUMN values starting from 1 I
Hey i am new to iOS development, in my app i want to fetch
Hey guys I'm tired and can't figure this one out so any help would
Hey all i am probably overthinking this but how can i check the textbox

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.