title: Gyroscope Android
body: <p>I am beginner to android , I have problem in the following example to print gyroscope values using android. </p>
  
  <pre><code>public class Gyro extends Activity implements OnClickListener,SensorEventListener {
  
     Button click;
  
     SensorManager sm;
  
     Sensor gyroscope; 
  
     int decide=1;
  
     Context c;
  
     TextView txt;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      setContentView(R.layout.activity_gyro);
  
      c = getApplicationContext();
  
  click = (Button)findViewById(R.id.btnAction);
  
  sm = (SensorManager)getSystemService(SENSOR_SERVICE);
  
  gyroscope = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
  
  txt = (TextView)findViewById(R.id.txt) ;
  
  click.setText("Start");
  click.setOnClickListener(this);
  }
  
  @Override
  public void onClick(View arg0) {
  
      if(decide==1)
      {
          sm.registerListener(Gyro.this,gyroscope,SensorManager.SENSOR_DELAY_NORMAL);
  
          click.setText("Stop");
          decide=0;
  
      }else if(decide==0){
  
          sm.unregisterListener(Accelerometer.this);
  
          click.setText("Start");
          decide=1;
      }
  }
  
  @Override
  public void onAccuracyChanged(Sensor sensor, int accuracy) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void onSensorChanged(SensorEvent event) {
  
      txt.setText(event.values[0]+"::"+event.values[1]+"::"+event.values[2]);
  
  }
  
  }
  </code></pre>
  
  <p>Code is not working .Any example ,tutorial would also be helpful .Thanks in advance.</p>