How to handle with multi buttons?
I´m using this code to change SoundOff to soundOff ON click
I dont now how to fix the error
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameover);
//setting the orientation to landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
ImageView medaille = (ImageView) findViewById(R.id.medaille);
//adding a click listener
//Define Logout
ImageButton LogOut = (ImageButton) findViewById(R.id.imageButton8);
//Define SoundOn
ImageButton SoundOn = (ImageButton) findViewById(R.id.imageButton9);
//Define SoundOff
ImageButton SoundOff = (ImageButton) findViewById(R.id.imageButton10);
//getting the button
ImageButton ButtonOk = (ImageButton) findViewById(R.id.imageButton11);
LogOut.setOnClickListener(this);
SoundOff.setOnClickListener(this);
SoundOn.setOnClickListener(this);
ButtonOk.setOnClickListener(this);
// Version
//define
TextView txtView = (TextView) findViewById(R.id.tv_current_score);
TextView txtsView = (TextView) findViewById(R.id.tv_current_score_value);
txtsView.setText(String.valueOf(GameView.score));
//Value
TextView myText = (TextView) findViewById(R.id.tv_best_score_value);
myText.setText(String.valueOf(GameView.Highscorer) );
TextView txtViews = (TextView) findViewById(R.id.tv_best_score);
}
@Override
public void onClick (View v){
//Define Logout
ImageButton LogOut = (ImageButton) findViewById(R.id.imageButton8);
//Define SoundOn
ImageButton SoundOn = (ImageButton) findViewById(R.id.imageButton9);
//Define SoundOff
ImageButton SoundOff = (ImageButton) findViewById(R.id.imageButton10);
//getting the button
ImageButton ButtonOk = (ImageButton) findViewById(R.id.imageButton11);
switch (v.getId()) {
case R.id.imageButton11:
//starting game activity
startActivity(new Intent(this, GameView.class));
break;
case R.id.imageButton4:
//Logout
startActivity(new Intent(this, GameLogout.class));
// do your code
break;
case R.id.imageButton8:
startActivity(new Intent(this, GameLogout.class));
break;
case R.id.imageButton9:
play = false;
SoundOn.setVisibility(View.GONE);//set visibility to false on create
SoundOff.setVisibility(View.VISIBLE);
break;
case R.id.imageButton10:
play = true;
SoundOn.setVisibility(View.VISIBLE);//set visibility to false on create
SoundOff.setVisibility(View.GONE);
}
}
I´m getting an error in NullPointerException in the "SoundOn.setVisibility(View.GONE);//set visibility to false on create"