Array of subclasses and onClick()
<p>I want to create by code an array of objects that are subclasses of Button.</p>

<pre><code>public class MyButton extends Button {
    private Context ctx;
    private int status;
    public MyButton(Context context) {
        super(context);
        ctx = context;
        status = 0;
    }

    private click() {
        status = 1;
        // OTHER CODE THAT NEEDS TO STAY HERE
    }
}
</code></pre>

<p>In the main activity I do this:</p>

<pre><code>public class myActivity extends Activity {
    private MyButton[] myButtons = new MyButton[100];

    @Override
    public onCreate(Bundle si) {
         super.onCreate(si);
         createButtons();
    }

    private void createButtons() {
         for (int w=0; w&lt;100; w++) {
             myButtons[w] = new MyButton(myActivity.this);
             myButtons[w].setOnClickListener(new View.onClickListener() {
                  public void onClick(View v) {
                  // ... (A)
                  }
             });
         }
    }
}
</code></pre>

<p>Now I want the click() method inside MyButton to be run each time the button is clicked.
Seems obvious but it is not at my eyes.</p>

<p>If I make the click() method public and run it directly from (A), I get an error because myButtons[w].click() is not static and cannot be run from there.</p>

<p>In the meantime, I an not able to understand where to put the code in the MyButton class to intercept a click and run click() from there. Should I override onClick? Or should I override onClickListener? Or what else should I do?</p>

<p>How can I run click() whenever one of myButtons[] object is clicked?</p>

<p>Thanks for the help.</p>
