Detect which layout is in use in an activity with two layouts <p>I have an activity called MainActivity that has two layouts.The previous activity has two buttons to choose which layout to be set.I need the button in MainActivity to act differently according to the layout in use, This is my code:</p> <pre><code> public class MainActivity extends Activity implements OnClickListener { Button shoot; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); if (extras != null) { int btnNumber = extras.getInt("button"); switch(btnNumber) { case 1 : setContentView(R.layout.first_layout); break; case 2 : setContentView(R.layout.second_layout); break; } } shoot=(Button)findViewById(R.id.button1); shoot.setOnClickListener(this); public void onClick(View arg0) { // TODO Auto-generated method stub switch(arg0.getId()) { case R.id.button1: // WHAT SHOULD THE CODE BE HERE break; } } </code></pre>