title: Add setOnClickListener on Android custom component
body: <p>When making a custom component for Android, as far as I understood, I need:</p>
  
  <ul>
  <li>one xml file with the layout for the component;</li>
  <li>one java class.</li>
  </ul>
  
  <p>Tried to make one, just for practice. Use two progressbars and one button in the XML, and create the class, than tried out in my main activity, worked fine.</p>
  
  <p>But now I'm loking how to set OnClickListener on my button through the activity, and in this part I'm lost.</p>
  
  <p>My loading_button.xml:</p>
  
  <pre><code>&lt;merge
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"&gt;
  
  &lt;RelativeLayout
      android:orientation="vertical"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
  
      &lt;ProgressBar
          style="?android:attr/progressBarStyleHorizontal"
          android:layout_width="match_parent"
          android:layout_height="4dp"
          android:progress="0"
          android:id="@+id/pg_top" /&gt;
  
      &lt;Button
          android:text="Button"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btn_ok"
          android:background="@color/colorPrimary"
          android:textColor="#ffffff"
          android:layout_below="@+id/pg_top"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;ProgressBar
          style="?android:attr/progressBarStyleHorizontal"
          android:layout_width="match_parent"
          android:layout_height="5dp"
          android:progress="0"
          android:id="@+id/pg_bottom"
          android:layout_below="@+id/btn_ok"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  
  &lt;/merge&gt;
  </code></pre>
  
  <p>Here the LoadingButton.java:</p>
  
  <pre><code>public class LoadingButton extends RelativeLayout{
  
  private ProgressBar pbTop;
  private ProgressBar pbBottom;
  private Button btnOk;
  
  private int pbTopProgress = 0;
  private int pbBottomProgress = 0;
  
  public LoadingButton(Context context, AttributeSet attrs) {
      super(context, attrs);
      View view = View.inflate(context, R.layout.loading_button, this);
  
      btnOk = (Button) view.findViewById(R.id.btn_ok);
      pbTop = (ProgressBar) view.findViewById(R.id.pg_top);
      pbBottom = (ProgressBar) view.findViewById(R.id.pg_bottom);
  
      btnOk.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              // Doing stuff ok
          }
      });
  
  }// LoadingButton
  }
  </code></pre>
  
  <p>The setOnClickListener in the class works, but how can I set it from my main activity?</p>
  
  <p>MainActivity:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      // My new component (it's id in activity_main.xml is 'lb') 
      LoadingButton lb = (LoadingButton) findViewById(R.id.lb);
  
      // QUESTION - how to make something like this with btnOk:
      lb.btnOkSetOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
            // Do stuff
         }
      });
    }
  }
  </code></pre>
  
  <p>If this is possible, how?</p>
  
  <p>If not, what is the right approach to make a custom component and set clickListeners on specific element of this component?</p>