Dynamic CheckedTextView in Kotlin
CheckedTextView is used to implement checkable interface where one can tick or check the needed or required items and leave out the rest.
In this article, we will be discussing how to make a CheckedTextView dynamically or programmatically.
The first step is to make or create a project in Android Studio. Here, we will be creating a project named DynamicCheckedTextView.
For creating a new project:
- Click on File, then New => New Project
- Then, check Include Kotlin Support and click next button.
- Select minimum SDK, whatever you need.
- Select Empty activity and then click finish.
Now, we need to modify our layout. For doing so : Go to app > res > layout and paste the following code:
Modify the activity_main.xml file
Next step is to add the strings which will be displayed when we check or uncheck our CheckedTextView.
Go to res/values/strings.xml and add the following lines.
Use CheckedTextView Code in MainActivity.kt file
The final step is to code our CheckedTextView. Open app/src/main/java/yourPackageName/MainActivity.kt