Dynamic CheckedTextView in Kotlin Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report CheckedTextView is an extension of TextView in Android that includes a checkmark, making it function like a checkbox. It is commonly used in list views where items can be selected or toggled between checked and unchecked states. Users can tap the text to change its checked status, and the checkmark updates accordingly. In this article, we will be discussing how to make a CheckedTextView dynamically or programmatically.Steps of ImplementationStep 1: Create a new projectTo create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.Step 2: Modify the activity_main.xml fileNow, we need to modify our layout. For doing so : Go to app > res > layout > activity_main.xml and paste the following code.activity_main.xml: XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/main" android:gravity="center" android:orientation="vertical" tools:context=".MainActivity"> </LinearLayout> Step 3: Use CheckedTextView Code in MainActivity.kt fileThe final step is to code our CheckedTextView. Navigate to app > src > main > java > {package-name} > MainActivity.kt.MainActivity.kt: Kotlin package org.geeksforgeeks.demo import android.os.Bundle import android.view.ViewGroup import android.widget.CheckedTextView import android.widget.LinearLayout import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val layout: LinearLayout = findViewById(R.id.main) val checkedTextView = CheckedTextView(this) checkedTextView.layoutParams = LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ) checkedTextView.text = "CheckedTextViewInKotlin" //initially the checkbox in unchecked checkedTextView.isChecked = false checkedTextView.setCheckMarkDrawable(android.R.drawable.checkbox_off_background) //Onclick event for checkbox checkedTextView.setOnClickListener { checkedTextView.isChecked = !checkedTextView.isChecked checkedTextView.setCheckMarkDrawable( if (checkedTextView.isChecked) android.R.drawable.checkbox_on_background else android.R.drawable.checkbox_off_background ) val msg = if (checkedTextView.isChecked) "View is: checked" else "View is: unchecked" Toast.makeText(this@MainActivity, msg, Toast.LENGTH_SHORT).show() } // Add Checkbox to RelativeLayout layout.addView(checkedTextView) } } Output: Create Quiz Comment A abhishek7 Follow 0 Improve A abhishek7 Follow 0 Improve Article Tags : Kotlin Kotlin Android Android-View Explore OverviewIntroduction to Kotlin4 min readKotlin Environment setup for Command Line2 min readKotlin Environment setup with Intellij IDEA2 min readHello World program in Kotlin2 min readBasicsKotlin Data Types3 min readKotlin Variables2 min readKotlin Operators4 min readKotlin Standard Input/Output4 min readKotlin Type Conversion2 min readKotlin Expression, Statement and Block4 min readControl FlowKotlin if-else expression4 min readKotlin while loop2 min readKotlin do-while loop2 min readKotlin for loop4 min readKotlin when expression6 min readKotlin Unlabelled break4 min readKotlin labelled continue4 min readArray & StringKotlin Array6 min readKotlin String4 min readFunctionsKotlin functions7 min readKotlin Default and Named argument7 min readKotlin Recursion3 min readKotlin Tail Recursion2 min readKotlin Lambdas Expressions and Anonymous Functions6 min readKotlin Inline Functions5 min readKotlin infix function notation5 min readKotlin Higher-Order Functions6 min readCollectionsKotlin Collections6 min readKotlin list : Arraylist6 min readKotlin list : listOf()7 min readKotlin Set : setOf()4 min readKotlin hashSetOf()4 min readKotlin Map : mapOf()5 min readKotlin Hashmap7 min readOOPs ConceptKotlin Class and Objects4 min readKotlin Nested class and Inner class3 min readKotlin Setters and Getters4 min readKotlin Class Properties and Custom Accessors3 min readKotlin Constructor6 min readKotlin Visibility Modifiers6 min readKotlin Inheritance10 min readKotlin Interfaces7 min readKotlin Data Classes3 min readKotlin Sealed Classes4 min readKotlin Abstract class5 min readEnum Classes in Kotlin4 min readKotlin extension function4 min readKotlin generics6 min readException HandlingKotlin Exception Handling - try, catch, throw and finally5 min readKotlin Nested try block and multiple catch block3 min readNull SafetyKotlin Null Safety7 min readKotlin Type Checking and Smart Casting3 min readKotlin Explicit Type Casting3 min readRegex & RangesKotlin Regular Expression4 min readKotlin Ranges3 min read Like