Issue
I am planning to display the version code on my xml files but I am have an error to display the text.
My Activity Code
val displayVersion = findViewById<TextView>(R.id.app_version)
val appVersion = getString(R.string.app_version)
val versionName: String = BuildConfig.VERSION_NAME
displayVersion.text = "$appVersion $versionName"
My XML Code
<TextView
android:id="@+id/app_version"
android:layout_below="@+id/splash_progressbar"
android:layout_width="match_parent"
android:layout_marginBottom="20dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="12sp"
tools:text="TextView"/>
Error Code
displayVersion.text = "$appVersion $versionName"
Maybe this error code are incorrect, because every-time I that code the app will works if the code exist the app will lunch but eventually it will automatically crash.
Solution
The reason for this error because I put the layout below to the code I provided above
I just put this code above setContentView(R.layout.layout_name)
setContentView(R.layout.layout_name) <-- This is the root cause of my concern
val displayVersion = findViewById<TextView>(R.id.app_version)
val appVersion = getString(R.string.app_version)
val versionName: String = BuildConfig.VERSION_NAME
displayVersion.text = "$appVersion $versionName"
My Error Code
val displayVersion = findViewById<TextView>(R.id.app_version)
val appVersion = getString(R.string.app_version)
val versionName: String = BuildConfig.VERSION_NAME
displayVersion.text = "$appVersion $versionName"
setContentView(R.layout.layout_name) <--This should be put above
Answered By - Clinton Canarias
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.