title: ImageButton OnClickListener Is Not Firing
body: <p>I've been pretty confused for a couple days now.</p>
  
  <p>A few days ago I started trying to extend the TableLayout view to make it collapsible. It sounded pretty straight forward.</p>
  
  <p>Problem:</p>
  
  <pre><code>protected void onFinishInflate()
  {
      super.onFinishInflate();
  
      ImageButton ib = (ImageButton) this.findViewById(R.id.collapse);
      // totally gayed
      ib.setOnClickListener(this.onButtonClick(ib));
  }
  
  //works
  public OnClickListener onButtonClick(ImageButton ib) {
      try {
          if (this.collapsed)
          {
              this.Build();
              ib.setImageResource(android.R.drawable.arrow_up_float);
          } else {
              this.Collapse();
              ib.setImageResource(android.R.drawable.arrow_down_float);
          }
      } catch (Exception e) {
          Log.e("MTK", e.toString() + " : " + e.getMessage() + " : " + e.getCause());
      }
      return null;
  }
  </code></pre>
  
  <p>So the funny thing is that the Table will open with all the rows gone except the header. The onClick method fires when the view is instantiated (alright..?).</p>
  
  <p>But after that I get nothing and I really have no idea what the problem is. I've tried a ton of stuff.</p>
  
  <p>Solution:</p>
  
  <pre><code>public View.OnClickListener onButtonClick(final CollapsibleTableLayout tbl, final ImageButton ib) {
          return new View.OnClickListener() { 
              public void onClick(View v) {
                  try {
                      if (tbl.collapsed == true)
                      {
                          tbl.Build();
                          tbl.collapsed = false;
                          ib.setImageResource(android.R.drawable.arrow_up_float);
                      } else {
                          tbl.Collapse();
                          tbl.collapsed = true;
                          ib.setImageResource(android.R.drawable.arrow_down_float);
                      }
                  } catch (Exception e) {
                      Log.e("MTK", e.toString() + " : " + e.getMessage() + " : " + e.getCause());
                  }
              }
          };
      }
  </code></pre>
  
  <p>turns out i wasn't returning the click handler. used to them working a little different in other languages.</p>
  
  <p>i thought if i did it that way i wouldnt be able to modify the class i was working in but you just have to pass final references to the click handler.</p>
  
  <p>hope this helps someone</p>