I’m new on Java and Android programming language and this is the first platform that I studied.
I want to ask, how can I access the event.values[1] in this method?
public void onSensorChanged(SensorEvent event) {synchronized (this){
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
return;
mAccVals.x = (float) (event.values[1] * FILTERING_FACTOR + mAccVals.x * (1.0 - FILTERING_FACTOR));
//mAccVals.y = (float) ((-event.values[1] * FILTERING_FACTOR + mAccVals.y * (1.0 - FILTERING_FACTOR)));
mAccVals.z = (float) (event.values[2] * FILTERING_FACTOR + mAccVals.z * (1.0 - FILTERING_FACTOR));
scene.camera().position.x = mAccVals.x * .2f;
scene.camera().position.z = mAccVals.z * .8f;
scene.camera().target.x = -scene.camera().position.x;
scene.camera().target.z = -scene.camera().position.z;
}
I want to get event.values[1] and then display it on a textview
protected void onCreateSetContentView()
{
setContentView(R.layout.custom_layout_example);
LinearLayout ll = (LinearLayout) this.findViewById(R.id.scene1Holder);
ll.addView(_glSurfaceView);
TextView myTextView = (TextView) findViewById(R.id.splashTitle);
myTextView.setText("Test " + event.values[1] );
return;
}
There’s any suggestion how can I solve this problem?
Thanks in advance
Create a field in your
Activityand assign it to yourR.id.splashTitle:Then set it’s text in
onSensorChanged()as follows:Or you may store most recent sensor’s values in a field:
To preserve right sequense of
onCreateandonSensorChangedyou may use an approach described in documentation: