title: Android development Linking XML button to Java
body: <p>I am new to android development, I am basically trying to create a very basic app which will enable the user to switch on their wifi. </p>
  
  <p>My XML file:</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" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="16dp"
      android:gravity="top"
      android:text="@string/welcome"
      android:textSize="25sp" /&gt;
  
  &lt;Button
      android:id="@+id/wifi_on"
      android:layout_width="150dp"
      android:layout_height="60dp"
      android:layout_below="@+id/textView1"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="112dp"
      android:text="@string/wifi_button" /&gt;
  </code></pre>
  
  <p>`  </p>
  
  <p>My Java file:</p>
  
  <p><code>package com.example.dosomething;</code></p>
  
  <p><code>import android.os.Bundle;</code>
  <code>import android.app.Activity;</code>
  <code>import android.view.Menu;</code>
  <code>import android.view.View;</code>
  <code>import android.view.View.OnClickListener;</code>
  <code>import android.widget.Button;</code></p>
  
  <p><code>public class MainActivity extends Activity implements OnClickListener {</code></p>
  
  <pre><code>protected Button wifi_on;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  
  @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;
  }
  
  @Override
  public void onClick(View v) {
      // TODO Auto-generated method stub
  
  
  }
  
  public Button getWifiOn(){
  
  
      return wifi_on;
  
  } 
  
  
  public void setWifiOn(Button on){
  
      wifi_on = on;
  
  
  }
  </code></pre>
  
  <p>}`</p>
  
  <p>My question is how can I refer to the button inside the XML file onto the java file to further tell it that if the button is clicked on it should turn on the wifi. Thanks.</p>