title: Android setOnClickListener method - How does it work?
body: <p>I have trouble understanding this code. I get that <code>findViewById</code> will get the button widget and then it'll cast it. Then, it's going to use the button to call the <code>setOnClickListener</code> method. However, I don't know what is that argument being passed into the <code>setOnClickListener</code> and I have never seen code like that before. How is it that it creates a new object but is able to create a method of its own within another method's argument? Would be great if someone could explain that. Also, what type of object is the <code>setOnClickListener</code> method taking in?</p>
  
  <pre><code>btn = (Button)findViewById(R.id.firstButton);
  btn.setOnClickListener(new View.OnClickListener()
  {
      @Override
      public void onClick(View v)
      {
          tv.setText(months[rand.nextInt(12)]);
          tv.setTextColor(Color.rgb(rand.nextInt(255)+1, rand.nextInt(255)+1, rand.nextInt(255)+1));
      }
  });
  </code></pre>