title: Custom Button onClickListener is static context?
body: <p>I have an activity that creates a custom button. 
  Here is the button class.</p>
  
  <p>In my main activity I have methods that allow the program to jump between activities, but the error I am getting is that I am referencing a non static method from a static context. Why is that? Isnt the button a new instance?</p>
  
  <pre><code>public class LoginButton extends Button {
  
  private DataAdapter myDataAdapter;
  
  private String LOG_TAG = "Login Button";
  
  private EditText myPasswordEditText;
  private EditText myUserEditText;
  
  Context ctx;
  
  
  public LoginButton(Context ctx, AttributeSet attrs) {
      super(ctx, attrs);
  
      this.ctx = ctx;
  
      setOnClickListener(clicker);
      myDataAdapter = new DataAdapter(ctx);
  }
  
  
  //Other way is to implement the OnClickListener and implement the onClick method.
  OnClickListener clicker = new OnClickListener() {
      public void onClick(View v) {
  
          if(CheckUsernameField() &amp;&amp; CheckPasswordField()){
  
              myDataAdapter.open();
  
              if(myDataAdapter.LoginToDB(myUserEditText.getText().toString(), myPasswordEditText.getText().toString())){
  
                  //TODO: Custom buttons have trouble getting context. My solution was to call different activities from static method, but that requires setting FLAG_ACTIVITY_NEW_TASK which is not recommended.
                  MainActivity.GoToBeginRunScreen(ctx);
                  CreateAlertDialog("Login successful");
              }
              else
                  CreateAlertDialog("Invalid username and password");
  
              myDataAdapter.close();
  
          }
          else
              CreateAlertDialog("Please enter a username and password");
  
      }
  };
  </code></pre>
  
  <p>Here is the code I am calling from the above button.</p>
  
  <pre><code>public void GoToBeginRunScreen(Context ctx){
      Intent intent = new Intent(ctx, BeginRunActivity.class);
      ctx.startActivity(intent);
  }
  </code></pre>