title: Android - I want to use the same XML layout for multiple buttons in my app
body: <p>I'm a little confused as to what I should be doing.  I've read about fragments and I'm not sure if I should be using them here.  I have 3 button in my main_layout file.  What I'm doing incorrectly (I know) is that I have 3 different (but really similar) result xml files and 3 activity.java files.  The result page is the same, just different text.  There's no reason to have so many java files etc.  I know there has to be a better way?</p>
  
  <p>In my main_layout.xml, I have 3 ImageButtons:</p>
  
  <p><img src="https://i.stack.imgur.com/f5UqL.png" alt="enter image description here"></p>
  
  <p>In my MainActivity.java:</p>
  
  <pre><code>ImageButton ib1 = (ImageButton) findViewById(R.id.imageButton1);
  ib1.setOnClickListener(this);
  
  ImageButton ib2 = (ImageButton) findViewById(R.id.imageButton2);
  ib2.setOnClickListener(this);
  
  ImageButton ib3 = (ImageButton) findViewById(R.id.imageButton3);
  ib3.setOnClickListener(this);
  
  public void onClick(View v) {
      if (v.getId() == R.id.imageButton1) {
          startActivity(new Intent(Main.this, OneInfo.class));
      } else if (v.getId() == R.id.imageButton2) {
          startActivity(new Intent(Main.this, TwoInfo.class));
      } else if (v.getId() == R.id.imageButton3) {
          startActivity(new Intent(Main.this, ThreeInfo.class));
  </code></pre>