Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with setVisibility on ImageButtons
    primarykey
    data
    text
    <p>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. </p> <p>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.</p> <p>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.</p> <p>optionsActivity.java (New):</p> <pre><code> 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 &amp; 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 &amp; 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; } }); } } } </code></pre> <p>options.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" &gt; &lt;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" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload