i want to trace a variable to see it changing
-
28-04-2021 - |
Domanda
I am new to java for android and come from an actionscript 3.0 background. I am playing with the sensor manager and want to trace my direction to see if its working and such.. below is the code i am using to detect a change in direction/heading and i am wondering how to actually see my direction variable change in real time either via a trace or a text out put right on the display of my device:
SensorEventListener listener = new SensorEventListener(){
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent evt) {
float vals[] = evt.values;
float direction = vals[0];
}
any help is greatly appreciated by this novice..
Soluzione
Assuming your code is in an Activity class, one thing you could do is:
@Override
public void onSensorChanged(SensorEvent evt) {
float vals[] = evt.values;
float direction = vals[0];
setTitle("Direction = " + direction);
}
This will display the direction on the Activity's title bar.
If you want to record the values of direction, do this instead:
@Override
public void onSensorChanged(SensorEvent evt) {
float vals[] = evt.values;
float direction = vals[0];
Log.d("A Log Tag", "Direction = " + direction);
}
That will log the values to LogCat, which you can view in eclipse.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow