Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating Textview based on sensordata
    primarykey
    data
    text
    <p>I'm trying to update a textview based on sensorinput - more precise pitch. I have no problem getting the sensor data, converting it to degrees and displaying it in a textview. The problem is, that I wan't different numbers displayed, based on the pitch in degrees. I have written a if-else if statement and placed it in the onsensorchanged, but apart from the initial number it does not update.</p> <pre><code> @Override public void onSensorChanged(SensorEvent event) { switch(event.sensor.getType()){ case Sensor.TYPE_ACCELEROMETER: for(int i =0; i &lt; 3; i++){ valuesAccelerometer[i] = event.values[i]; } break; case Sensor.TYPE_MAGNETIC_FIELD: for(int i =0; i &lt; 3; i++){ valuesMagneticField[i] = event.values[i]; } break; } boolean success = SensorManager.getRotationMatrix( matrixR, matrixI, valuesAccelerometer, valuesMagneticField); if(success){ SensorManager.getOrientation(matrixR, matrixValues); // Float to double double pitch = Math.toDegrees(matrixValues[1]); // 1 decimal pitch = Math.abs(round(pitch, 0)); //set textview vinkel to degrees vinkel.setText(String.valueOf(pitch)); // find tubesize from edittext String tubesizestring = tubesize.getText().toString(); if(tubesizestring=="1000"){ if(pitch&gt;=0.6){ kwh.setText("2,69"); }else if(pitch&gt;=1.0){ kwh.setText("3,47"); }else if(pitch&gt;=2.0){ kwh.setText("4,90"); }else if(pitch&gt;=5.0){ kwh.setText("7,75"); }else if(pitch&gt;=10.0){ kwh.setText("10,96"); }else if(pitch&gt;=20.0){ kwh.setText("15,50"); }else if(pitch&gt;=30.0){ kwh.setText("18,99"); }else{ kwh.setText("more than 30 degrees"); } } } </code></pre> <p>I hope it is clear what I'm trying to do. Othervise please ask</p> <p>Hope somebody can point me in the right direction</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload