title: Passing an object of MainActivity through View.OnClickListener()
body: <p>Below is an example of My app's MainActivity.java:</p>
  
  <pre><code>/*imports and other stuffs*/
  
  public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
  Button myButton;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      myButton = (Button) findViewById(R.id.first_button);
     // myButton.setOnClickListener(this); by using it, app works as desired.
  
  
      myButton.setOnClickListener(new MainActivity()); //What's wrong with this piece of codes?
  
  }
  
  @Override
  public void onClick(View v) {
      if(v.getId()==R.id.first_button){
          Toast.makeText(this, "Made it", Toast.LENGTH_SHORT).show();
      }
  
  }
  </code></pre>
  
  <p>As setOnClickListener() method requires an object of a class that implements View.setOnClickListener, it can be handled with a custom class implements View.setOnClickListener, but my question, as a beginner, is what's going on actually, while passing an object of MainActivity?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>But if I pass an object of another class and pass that one, the code works perfectly, doesn't it? and what about those codes:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  Button myButton;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      myButton = (Button) findViewById(R.id.first_button);
  
  
      myButton.setOnClickListener(new MyClass());
  
  
  }
  
  class MyClass implements View.OnClickListener{
  
      @Override
      public void onClick(View v) {
          Log.d("buttontest","Working Perfectly");
      }
  }
  </code></pre>
  
  <p>}</p>