android - Barometer App - Where to from here? -
i working on basic barometer app , have run slight snag. want take data being received , have run through text view have setup pressure variable. here code point:
import android.app.activity; import android.hardware.sensor; import android.hardware.sensorevent; import android.hardware.sensoreventlistener; import android.hardware.sensormanager; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.textview; public class barometer extends activity { textview barotext, timetext; button refresh; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.barometer_layout); uivars(); sensormanager sensormanager = (sensormanager) getsystemservice(sensor_service); sensor sensor = sensormanager.getdefaultsensor(sensor.type_pressure); sensormanager.registerlistener(new mylistener(), sensor, sensormanager.sensor_delay_normal); } public void uivars(){ barotext = (textview) findviewbyid(r.id.pressuretxt); timetext = (textview) findviewbyid(r.id.timetxt); refresh = (button) findviewbyid(r.id.barorefreshbtn); } class mylistener implements sensoreventlistener { @override public void onaccuracychanged(sensor sensor, int accuracy) { // todo } @override public void onsensorchanged(sensorevent event) { long timestamp = event.timestamp; float value = event.values[0]; // values } } }
i understand silly missing wanted second set of eyes looking @ it. - if running android studio ide.
this should work:
@override public void onsensorchanged(sensorevent event) { long timestamp = event.timestamp; float value = event.values[0]; string valuestring = string.valueof(value); barotext.settext(valuestring); }
if want display value in textview.
Comments
Post a Comment