我将 Java 和 Kotlin 用于经验不足的个人项目,我可能会在这方面使用您的帮助。我想做的是从 Estimote 信标读取遥测数据(温度、压力、光照水平)。我已经设法将值和更新值放入文本视图中。
现在我想在这一点上获取 IF 条件(稍后我将尝试将它们保存并上传到 Firebase 数据库)。基本上我想检查遥测值之一是高于还是低于双精度数。例如。如果光照水平低于 6 勒克斯,请写“低于 6!”,如果高于“超过 6!”
val scanner = EstimoteBluetoothScannerFactory(applicationContext).getSimpleScanner()
val scanHandler = scanner.estimoteTelemetryFullScan()
.withBalancedPowerMode()
.withOnPacketFoundAction {
var temperature: TextView = findViewById<TextView>(R.id.temperature)
temperature.setText("Temperature: ${it.temperatureInCelsiusDegrees}")
var magnetometer: TextView = findViewById<TextView>(R.id.magnetometer)
magnetometer.setText("Magnetometer: ${it.magnetometer}")
var pressure: TextView = findViewById<TextView>(R.id.pressure)
pressure.setText("Pressure: ${it.pressure}")
var ambientLight: TextView = findViewById<TextView>(R.id.ambientLight)
ambientLight.setText("Ambient Light: ${it.ambientLightInLux}")
var motionState: TextView = findViewById<TextView>(R.id.motionState)
motionState.setText("Motion State: ${it.motionState}")
}
.start()
if(ambientLight > 6) {
var checkLight: TextView = findViewById<TextView>(R.id.checkLight)
checkLight.setText("More than 6!")
}else{
var checkLight: TextView = findViewById<TextView>(R.id.checkLight)
checkLight.setText("Less than 6!")
}
此代码不会更新 textview 值