所以我一行一行地跟着一個簡單的教程,但得到了錯誤信息: 類stepcounter必須被聲明爲abstract或在sensorevent偵聽器中實現抽象方法onAccuracyChanged(sensor,int)。方法的Android抽象類錯誤
編輯:/ /我改變公共類爲公共抽象類,但我試圖將其添加到清單,但沒有被接受,因爲它不是一個具體的類,所以沒有打開一個按鈕點擊活動,應用程序崩潰。
下面是代碼:
public class StepCounter extends Activity implements SensorEventListener {
private TextView textView;
private SensorManager mSensorManager;
private Sensor mStepCounterSensor;
private Sensor mStepDetectorSensor;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stepcounter);
textView = (TextView) findViewById(R.id.textView47);
mSensorManager = (SensorManager)
getSystemService(Context.SENSOR_SERVICE);
mStepCounterSensor = mSensorManager
.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
mStepDetectorSensor = mSensorManager
.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
}
public void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
float[] values = event.values;
int value = -1;
if (values.length > 0) {
value = (int) values[0];
}
if (sensor.getType() == Sensor.TYPE_STEP_COUNTER) {
textView.setText("Step Counter Detected : " + value);
} else if (sensor.getType() == Sensor.TYPE_STEP_DETECTOR) {
// For test only. Only allowed value is 1.0 i.e. for step taken
textView.setText("Step Detector Detected : " + value);
}
}
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mStepCounterSensor,
SensorManager.SENSOR_DELAY_FASTEST);
mSensorManager.registerListener(this, mStepDetectorSensor,
SensorManager.SENSOR_DELAY_FASTEST);
}
protected void onStop() {
super.onStop();
mSensorManager.unregisterListener(this, mStepCounterSensor);
mSensorManager.unregisterListener(this, mStepDetectorSensor);
}
}
不要我把什麼onAccuraryChanged()任何你想要的程序做 – Bimal 2015-02-10 21:00:52
時的傳感器更改的準確性。如果你不想做任何事情,你可以把它留空,但你仍然需要繼承這個方法(寫出來)。 – IntegralOfTan 2015-02-10 21:02:14