title: Android: When using setOnCheckedChangeListener on switches I get 'Cannot Resolve Symbol Error'
body: <pre><code>package com.example.koustav.myapplication;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Switch;
  import android.widget.TextView;
  import android.widget.CompoundButton;
  import android.widget.CompoundButton.OnCheckedChangeListener;
  
  public class MainActivity extends Activity
  {
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      Switch swi = (Switch) findViewById(R.id.swch);
      swi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
      {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) //Line A
          {
  
          }
      });
  
      public void onClick(View view)
      {
          boolean isOn = ((Switch) view).isChecked();
  
          if (isOn)
          {
              ((TextView) findViewById(R.id.largey)).setTextColor(getResources().getColor(R.color.black));
          }
          else
          {
              ((TextView) findViewById(R.id.largey)).setTextColor(getResources().getColor(R.color.white));
          }
  
      }
  
  }
  </code></pre>
  
  <p>I am using Android Studio for this project. I have searched the interwebs for a solution extensibly but could not find one. </p>
  
  <p>I have been trying to use <code>setOnCheckedChangeListener</code> for a <code>Switch</code> object. However no matter what I try, I always get a <strong>Cannot Resolve Symbol 'setOnCheckedChangeListener'</strong> error. Also, at the line A, the object buttonView is underlined red giving the same error <strong>Cannot Resolve Symbol 'buttonView'</strong>.</p>
  
  <p>I have imported the necessary (and recommended as answers for other people) classes. I am working with APIs for android 4.0 and above. I basically want the <code>onClick</code> method to be re-implemented via the listener because the listener works with both clicks and swipes whereas <code>onClick</code> only works with clicks and not swipes.</p>