How to get sensor value as variable -
this stupid question cannot handle myself. managed value of light sensor. need value variable cannot access variable x. me out?
public class lightwakeup extends appcompatactivity {
imagebutton imagebutton; intent navrat; mediaplayer mp; textview text; sensormanager sensormanager; sensor sensor; float x; public float c; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_light_wakeup); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); text = (textview)findviewbyid(r.id.textview); //zapnuti hudby mp = mediaplayer.create(this, r.raw.hypnothis); mp.setvolume(50, 50); mp.start(); sensormanager = (sensormanager) getsystemservice(context.sensor_service); sensor = sensormanager.getdefaultsensor(sensor.type_light); text.settext(string.valueof(c)); imagebutton = (imagebutton) findviewbyid(r.id.imagebutton); imagebutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mp.stop(); navrat = new intent(getapplicationcontext(), mainpage.class); startactivity(navrat); } }); } public void onresume() { super.onresume(); sensormanager.registerlistener(lightlistener, sensor, sensormanager.sensor_delay_normal); } public void onstop() { super.onstop(); sensormanager.unregisterlistener(lightlistener); } public sensoreventlistener lightlistener = new sensoreventlistener() { public void onaccuracychanged(sensor sensor, int acc) { } public void onsensorchanged(sensorevent event) { x = event.values[0]; text.settext((int)x); } };
}
you need set variable x public modifier:
public float x;
by default, class variables without modifiers set "internal" in c#. can see variable modifiers @ https://msdn.microsoft.com/en-us/library/ms173121.aspx
Comments
Post a Comment