Advanced Android: [Lesson #][Step #][description]
Productivix opened this issue · 2 comments
Describe the problem
A clear and concise description of what the problem is.
it seem to be written in Java and when you copy it in android studio, it converts it in Kotlin , with more or less success
In which lesson and step of the codelab can this issue be found?
Lesson number + step number. (e.g., Lesson 1.1, Step 1.3) : Advanced Android 03.1: Getting sensor data
How to reproduce?
What are the exact steps to reproduce the problem? just copy your code
Versions
- What version of Android Studio are you using?
- What API level are you targeting?
Additional information
Add any other context about the problem here.
codelab: advanced-android
The best code I add is :
class MainActivity : AppCompatActivity() {
private var mSensorManager: SensorManager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mSensorManager = this.getSystemService(Context.SENSOR_SERVICE) as SensorManager?
val sensorList: List<Sensor> = mSensorManager.getSensorList(Sensor.TYPE_ALL)
rather :
class MainActivity : AppCompatActivity() {
private var mSensorManager: SensorManager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mSensorManager = this.getSystemService(SENSOR_SERVICE) as SensorManager?
val sensorList: List = mSensorManager.getSensorList(Sensor.TYPE_ALL)
val sensorText = StringBuilder()
for (currentSensor in sensorList) {
sensorText.append(currentSensor.name).append(
System.getProperty("line.separator"))
}
val sensorTextView = findViewById(R.id.sensor_list) as TextView
sensorTextView.text = sensorText
}
after debug it is :
class MainActivity : AppCompatActivity() {
private var mSensorManager: SensorManager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mSensorManager = this.getSystemService(SENSOR_SERVICE) as SensorManager?
val sensorList = mSensorManager?.getSensorList(Sensor.TYPE_ALL)
val sensorText = StringBuilder()
if (sensorList != null) {
for (currentSensor in sensorList) {
sensorText.append(currentSensor.name).append(
System.getProperty("line.separator"))
}
}
val sensorTextView = findViewById(R.id.sensor_list) as TextView
sensorTextView.text = sensorText
}