I need this miss button to be GONE on the initial screen, then appear when toggle button is toggled, and be GONE again when re-toggled.
The problem which persists atm is that the button isn’t gone initially on the initial screen, i have to press the toggle button twice, for it to be gone.
here’s the code:
toggle = (ToggleButton) findViewById(R.id.bRedGreen);
toggle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pluskugle = (Button) findViewById(R.id.bBallhole);
minuskugle = (Button) findViewById(R.id.bBallhole);
pluskegle = (Button) findViewById(R.id.bKegle);
minuskegle = (Button) findViewById(R.id.bKegle);
plusmidkegle = (Button) findViewById(R.id.bKeglemid);
minusmidkegle = (Button) findViewById(R.id.bKeglemid);
bottomlayout = (LinearLayout) findViewById(R.id.bottomlayout);
miss = (Button) findViewById(R.id.bMiss);
if(toggle.isChecked())
{
minuskugle.setBackgroundResource(R.drawable.redballinhole);
minuskegle.setBackgroundResource(R.drawable.redkegle);
minusmidkegle.setBackgroundResource(R.drawable.midkegleminus);
miss.setBackgroundResource(R.drawable.missbutton);
miss.setVisibility(View.VISIBLE);
}
else
{
pluskugle.setBackgroundResource(R.drawable.whiteballinhole);
pluskegle.setBackgroundResource(R.drawable.kegleb);
plusmidkegle.setBackgroundResource(R.drawable.midkegleplus);
miss.setVisibility(View.GONE);
}
}
});
}
The behavior you’re seeing is the result of two things:
-The reason the button is initially visible is that you don’t have android:visibility=”gone” in your XML, and the code to set it invisible hasn’t fired, because no click has occurred yet.
-The reason you have to hit the toggle button twice to set it to invisible: The first click switches the toggle from not checked to checked, so the code sets the button (which is already visible) to visible. The SECOND click is the first time that an onClick fires and the toggle button isn’t checked. That’s when you actually see the button go invisible.
To fix, just add “android:visibility=”GONE” as an attribute to the miss button in your layout XML.