title: Calling button onclick event from another class
body: <p>I have made a login app and it holds two buttons: login and register ..
  i have to made another class named Registerclass and wrote all that button event code in that class ..
  now i want to call that button in my main to get that button working in the main! How to call a button event from another class into the main?</p>
  
  <p>here's my main class code :</p>
  
  <pre><code>    public class MainActivity extends Activity  {
  
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
  
              Registerclass rg = new Registerclass();
              View v = null; // this is not working
              rg.goButtonClicked(v); //guide me how to call a button click listener from another class i.e Registerclass
          }
  
  
  
  
  
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.main, menu);
              return true;
          }
  
      }
  </code></pre>
  
  <p>here's my second class named Registerclass :</p>
  
  <pre><code>    public class Registerclass extends Activity{
  
  
          @Override
  
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_main);
  
  
  
                  Button register=(Button)findViewById(R.id.bregister);
                  register.setOnClickListener(new View.OnClickListener() {
  
                      @SuppressWarnings("deprecation")
                      @Override
  
                      public void onClick(View arg0) {
                          // TODO Auto-generated method stub
                          LinearLayout layout = new LinearLayout(Registerclass.this);
                          layout.setOrientation(LinearLayout.VERTICAL);
  
                          final AlertDialog alert = new AlertDialog.Builder(Registerclass.this).create();
                          final EditText login = new EditText(Registerclass.this);
                          login.setHint("Enter Login id");
                          login.setHintTextColor(Color.BLUE);
                          layout.addView(login);                          
                          final EditText pass = new EditText(Registerclass.this);
                          pass.setHint("Enter Password");
                          pass.setHintTextColor(Color.BLUE);
                          layout.addView(pass);
  
                          alert.setTitle("REGISTER");                         
                          alert.setView(layout);
  
                          //alert.setButton("Register", new DialogInterface.OnClickListener() {
  
                              //@Override
                              //public void onClick(DialogInterface arg0, int arg1) {
                               //TODO Auto-generated method stub
                               //String user=login.getText().toString();
                               //String pswd=pass.getText().toString();
  
  
                      //}
                  //});
                          alert.show();
                      }
  
                  });
              }
  
  
              }
  </code></pre>
  
  <p>here's my xml : </p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity"
      android:background="@drawable/background" &gt;
  
      &lt;EditText
          android:id="@+id/etlogin"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="186dp"
          android:background="#ffffff"
          android:ems="10"
          android:hint="Login "
          android:inputType="textEmailAddress"
          android:textSize="30dp"
          android:typeface="sans" /&gt;
  
      &lt;EditText
          android:id="@+id/etpass"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/etlogin"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="14dp"
          android:background="#ffffff"
          android:ems="10"
          android:hint="Password "
          android:inputType="textPassword"
          android:textSize="30dp"
          android:typeface="sans" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
      &lt;Button
          android:id="@+id/blogin"
          style="?android:attr/buttonStyleSmall"
          android:layout_width="100dp"
          android:layout_height="30dp"
          android:layout_alignLeft="@+id/etpass"
          android:layout_below="@+id/etpass"
          android:layout_marginLeft="19dp"
          android:layout_marginTop="16dp"
          android:background="#b5ee7e"
          android:text="Login" /&gt;
  
      &lt;Button
          android:id="@+id/bregister"
          android:layout_width="100dp"
          android:layout_height="30dp"
          android:layout_alignBaseline="@+id/blogin"
          android:layout_alignBottom="@+id/blogin"
          android:layout_marginLeft="20dp"
          android:layout_toRightOf="@+id/blogin"
          android:background="#7EC0EE"
  
          android:text="Register" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>