The question is probably elementary, but for some reason the code in the switch-case does not work with OnClickListener implemented in the activity.
public class MainActivity extends Activity implements View.OnClickListener { Button btn1; Button btn2; Button btn3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1 = (Button)findViewById(R.id.button1); btn2 = (Button)findViewById(R.id.button2); btn3 = (Button)findViewById(R.id.button3); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button1: btn1.setVisibility(View.GONE); btn2.setVisibility(View.VISIBLE); break; case R.id.button2: btn2.setVisibility(View.GONE); btn1.setVisibility(View.VISIBLE); break; case R.id.button3: Toast toast = Toast.makeText(this, "this is toast", Toast.LENGTH_SHORT); toast.show(); break; default: Toast toast2 = Toast.makeText(this, "this is toast2", Toast.LENGTH_SHORT); toast2.show(); break; } } } Although, if you change the code somewhat: remove the implementation and change the visibility of the buttons in the methods defined via xml in "onClick", everything works. Missed something with a listener or an error in a swicth-case?