android - How to make text view display temperature data from another method? -
here entire code app. don't beleive have play method:
package com.solomonreedstudios.thermometer; import android.content.context; import android.hardware.sensor; import android.hardware.sensorevent; import android.hardware.sensoreventlistener; import android.hardware.sensormanager; import android.media.audiomanager; import android.media.soundpool; import android.os.bundle; import android.os.countdowntimer; import android.support.v7.app.actionbaractivity; import android.view.view; import android.widget.textview; public class main extends actionbaractivity implements sensoreventlistener { private sensormanager msensormanager; private sensor mtemperature; public textview tv1; public textview tv2; public textview tv3; soundpool beepint; int beep; @override public final void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_sensor_actvity); tv3 = (textview) findviewbyid(r.id.mtextfield); beepint = new soundpool(10, audiomanager.stream_music, 0); beep = beepint.load(this, r.raw.beep, 1); // instance of sensor service, , use instance of // particular sensor. msensormanager = (sensormanager) getsystemservice(context.sensor_service); mtemperature = msensormanager.getdefaultsensor(sensor.type_ambient_temperature); } @override public final void onaccuracychanged(sensor sensor, int accuracy) { // here if sensor accuracy changes. } @override public final void onsensorchanged(sensorevent event) { // sensor data. float lux = event.values[0]; float fahrenheit = lux * 9 / 5 + 32; tv1 = (textview) findviewbyid(r.id.text1); tv1.settext(string.valueof(lux)); tv2 = (textview) findviewbyid(r.id.textview2); tv2.settext(string.valueof(fahrenheit)); } @override protected void onresume() { // register listener sensor. super.onresume(); msensormanager.registerlistener(this, mtemperature, sensormanager.sensor_delay_normal); } @override protected void onpause() { // sure unregister sensor when activity pauses. super.onpause(); msensormanager.unregisterlistener(this); } public final void collectdata(view view) { new countdowntimer(300, 1000) { public void ontick(long millisuntilfinished) { tv3.settext("seconds remaining until reading: " + millisuntilfinished / 1000); } public void onfinish() { beepint.play(beep, 1, 1, 1, 0, 1); tv3.settext("your temperature " + mtemperature); } }.start(); } }
could help?
Comments
Post a Comment