title: Android development - Implementing onClickListener in my MainActivity
body: <p>This might be more of a question about class structure but I am trying to add a simple on click listener to the following piece of code. Once clicked it will change the "SENSOR_DELAY_FASTEST" value to "SENSOR_DELAY_NORMAL". So I can toggle on the fly. But as I am in MainActivity i cannot implement onClickListener. Could anyone give me any pointers as to how I could handle this? </p>
  
  <p>As I said. It might just be my lack of Java knowledge hindering me here. Perhaps it is better to setup another class to handle the clicks?</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements SensorEventListener {
  
  private TextView xText, yText, zText;
  private Sensor accelerometerSensor;
  private SensorManager sensorManager;
  
  @Override
  public void onSensorChanged(SensorEvent event) {
  
      // display the sensor values in the x,y and z text views
      xText.setText("X: " + event.values[0]);
      yText.setText("Y: " + event.values[1]);
      zText.setText("Z: " + event.values[2]);
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      // create sensor manager
      sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
  
      // create accelerometer sensor
      accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  
      // register listener
      sensorManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_FASTEST);
  
      // assign text views
      xText = (TextView)findViewById(R.id.xText);
      yText = (TextView)findViewById(R.id.yText);
      zText = (TextView)findViewById(R.id.zText);
  }
  }
  </code></pre>