title: how to add button click event in android studio
body: <p>So I have done some research, and after defining you button as an object by the code</p>
  
  <pre><code>private Button buttonname;
  buttonname = (Button) findViewById(R.id.buttonnameinandroid) ;
  </code></pre>
  
  <p>here is my problem</p>
  
  <pre><code>buttonname.setOnClickListener(this); //as I understand it, the "**this**" denotes the current `view(focus)` in the android program
  </code></pre>
  
  <p>then your <code>OnClick()</code> event...</p>
  
  <p>Problem:</p>
  
  <p>When I type in the "this", it says:</p>
  
  <pre><code>setOnClickListener (Android.View.view.OnClickListener) in View cannot be applied to (com.helloandroidstudio.MainActivity)
  </code></pre>
  
  <p>I have no idea why?</p>
  
  <p>here is the code from the .java file</p>
  
  <pre><code>import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class MainActivity extends ActionBarActivity {
  
      private Button btnClick;
      private EditText Name, Date;
      private TextView msg, NameOut, DateOut;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          btnClick = (Button) findViewById(R.id.button) ;
          btnClick.setOnClickListener(this);
          Name = (EditText) findViewById(R.id.textenter) ;
          Date = (EditText) findViewById(R.id.editText) ;
          msg = (TextView) findViewById(R.id.txtviewOut) ;
          NameOut = (TextView) findViewById(R.id.txtoutName) ;
          DateOut = (TextView) findViewById(R.id.txtOutDate) ;
          if (savedInstanceState == null) {
              getSupportFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment())
                      .commit();
          }
      }
  
      public void onClick(View v)
      {
          if (v == btnClick)
          {
              if (Name.equals("") == false &amp;&amp; Date.equals("") == false)
              {
                  NameOut = Name;
                  DateOut = Date;
                  msg.setVisibility(View.VISIBLE);
              }
              else
              {
                  msg.setText("Please complete both fields");
                  msg.setVisibility(View.VISIBLE);
              }
          }
          return;
  
      }
  </code></pre>