package com.example.ritwik.letswalk;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements SensorEventListener{
TextView tv_steps;
SensorManager sensorManager;
boolean running=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_steps=(TextView) findViewById(r.id.tv_steps);
sensorManager=(SensorManager) getSystemService(Context.SENSOR_SERVICE);
}
@Override
protected void onResume()
{
super.onResume();
running=true;
Sensor countSensor=sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
if(countSensor==null){
sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
}
else
Toast.makeText(this, "Sensor Not Found",Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause()
{
super.onPause();
running=false;
}
@Override
protected void onSensorChangeed(SensorEvent event)
{
if(running)
{
tv_steps.setText(String.valueOf(event.values[0]));
}
}
}
代码有以下错误
错误:(21、15)错误:找不到符号类TextView错误:任务':app:compileDebugJavaWithJavac'的执行失败。编译失败;有关详细信息,请参阅编译器错误输出。错误:(12, 5) 错误: 找不到符号类 TextView 错误:(43, 37) 错误: 找不到符号类 SensorEvent 错误:(11, 8) 错误: MainActivity 不是抽象的并且没有覆盖抽象方法 onAccuracyChanged(Sensor ,int) in SensorEventListener 错误:(21, 39) 错误: 包 r 不存在 错误:(42, 5) 错误: 方法没有覆盖或实现超类型中的方法