// activity_cheat.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/api_level"
tools:text="Api level" >
</TextView>
// CheatActivity.kt in OnCreate
val apiLevel : TextView = findViewById(R.id.api_level)
val buildNumber = Build.VERSION.SDK_INT.toString()
apiLevel.text = "API Level: $buildNumber"
3 Likes
I have got warning :
do not concatenate text displayed with settext. use resource string with placeholders.
so I fix this like that:
// activity_cheat.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/api_level"/>
</TextView>
// CheatActivity.kt in OnCreate
val apiLevel : TextView = findViewById(R.id.api_level)
val buildNumber = Build.VERSION.SDK_INT.toString()
apiLevel.text = getString(R.string.api_level, buildNumber)
and in strings.xml
<string name="api_level">Api Level %1$S</string>