title: Accessing activity from custom button
body: <p>Maybe I'm missing sth here but here it is. Let say I extended Button</p>
  
  <pre><code>    public class MyButton extends Button {
          ...
          public MyButton(Context context, AttributeSet attrs) {
              super(context, attrs);
              ...
          }
      }
  </code></pre>
  
  <ol>
  <li>If MyButton is in e.g. MyActivity I can simply cast context to activity. </li>
  <li>Now if MyButton is part of MyDialog (extends Dialog), context.getClass() will point to ContextThemeWrapper and I can not get activity. </li>
  </ol>
  
  <p>So how can I get instance of dialog or activity in the second case?</p>
  
  <p><strong>EDIT</strong>
  Ok more code to better illustrate what I wanted to do:</p>
  
  <pre><code>public class MyDialog extends Dialog {
      private MyButton myButton;
  
      public MyDialog(Context context) {
          super(context)  
  
          this.setContentView(R.layout.my_dialog);
          this.setTitle("My Dialog");
  
          myButton = (MyButton) findViewById(R.id.my_button);
      }
  }
  
  public class MyButton extends Button implements Command {
      private MyActivity myActivity;
  
      public MyButton(Context context, AttributeSet attrs) {
          super(context, attrs);
  
          System.out.println(context instanceof ContextThemeWrapper); // TRUE
          System.out.println(context instanceof Activity); // FALSE
  
          myActivity = ??? // or myDialog = ???
      }
  
      @Override
      public void execute() {
          MyDialog myDialog = myActivity.getMyDialog();
          myDialog.cancel();
      }
  
  }
  </code></pre>
  
  <p>and somewhere in other class after connecting listener:</p>
  
  <pre><code>@Override
  public void onClick(View v) {
      Command command = (Command) v;
      command.execute();
  }
  </code></pre>