title: Listener for the button of external Layout
body: <p>Hello I have a project in which one <code>Activity</code> and several <code>layout</code>. In the layouts contain various elements, such as buttons. I can not add buttons to these listeners from the main <code>Activity</code>. The <code>method onClick()</code> is used in the Activity (Activity implements <code>View.OnClickListener</code>)</p>
  
  <pre><code>public class MainActivity extends Activity implements View.OnTouchListener {
  //....
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          FrameLayout mainLayout = (FrameLayout) findViewById(R.id.container);
          mainLayout.setOnTouchListener(this);
          LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View one = (View) LayoutInflater.from(this).inflate(R.layout.one, null);
  
          flipper = (ViewFlipper) findViewById(R.id.viewFlip);
  
          int layouts[] = new int[]{R.layout.one, R.layout.two, R.layout.three};
          for (int layout : layouts) {
              flipper.addView(inflater.inflate(layout, null));
          }
  
  
          conBut = (Button) one.findViewById(R.id.conBut2);
          conBut.setOnClickListener(new listen());
      }
  
  
      private class listen implements View.OnClickListener {
          @Override
          public void onClick(View view) {
            // ....
          }
      }
  
     //....
  }
  </code></pre>
  
  <p>The result is a button, without action. Please, help me.</p>
  
  <p>UPD1:</p>
  
  <pre><code>public boolean onTouch(View view, MotionEvent event) {
      switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
              fromPosition = event.getX();
              break;
          case MotionEvent.ACTION_MOVE:
              float toPosition = event.getX();
              if ((fromPosition - MOVE_LENGTH) &gt; toPosition) {
                  fromPosition = toPosition;
                  flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.go_next_in));
                  flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.go_next_out));
                  flipper.showNext();
              } else if ((fromPosition + MOVE_LENGTH) &lt; toPosition) {
                  fromPosition = toPosition;
                  flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.go_prev_in));
                  flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.go_prev_out));
                  flipper.showPrevious();
              }
          default:
              break;
      }
      return true;
  }
  </code></pre>
  
  <p>UPD2</p>
  
  <pre><code>    public class MainActivity extends Activity implements View.OnTouchListener {
  private class listen implements View.OnClickListener {
      @Override
      public void onClick(View view) {
          makeMsg("Hello from onClick!", Toast.LENGTH_LONG);
          switch (view.getId()) {
              case R.id.conBut2: {
                  makeMsg("Hello by Button2!", Toast.LENGTH_LONG);
                  case R.id.regRad: {
                      makeMsg("Hello by RadioButton!", Toast.LENGTH_LONG);
                  }
              }
              ;
              break;
  
  
          }
      }
  }
  
      private void makeMsg(String txt, int dur) {
          Toast.makeText(this, txt, dur).show();
      }
  }
  </code></pre>