

Setting text of CheckedTextView In Java class: CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView) // initiate a CheckedTextView We can set the text in xml as well as in the java class. In the above code of checkMark we also used text attribute. text: This attribute is used to set the text in a CheckedTextView. tChecked(true) // set current state to true for CheckedTextViewĤ. CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView) // initiate a CheckedTextView Use the below code to set the checked property to true programmatically. In the above code of checkMark we also used this attribute. By default the value of this attribute is false. We can also change the state in Java class by using setChecked() method. checked: This attribute is used to set the current state of the CheckedTextView. tCheckMarkDrawable(R.drawable.checked) // set drawwable for check mark for CheckedTextViewģ. Setting checkMark In Java Class: CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView) // initiate a CheckedTextView PS: First save the image name as checked in drawable folder before using below code. checkmark: This attribute is used to set the drawable for the check mark. id: This attribute is used to uniquely identify a CheckedTextView.Ģ. Now let’s we discuss some important attributes that helps us to configure a CheckedTextView in your xml file.ġ. You can also download the image by click on it below.ĬheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView) // initiate a CheckedTextViewīoolean checkedValue = simpleCheckedTextView.isChecked() // check current state of CheckedTextView Very Important Note: Before using any code on this article make sure to download this image and save it in your drawable folder named as checked. Another thing is we can’t change the state of check mark only by clicking on the UI, instead we have to use a listener to do that. Important Note: In CheckedTextView we have to set android:checkMark attribute to provide a graphic or drawable otherwise it will not show the check mark and behaves like a normal TextView. checkmark attribute is used to provide a graphic or a drawable to CheckedTextView. It is mainly used in a ListView where we want to show which item is selected or not. In Android, CheckedTextView is an extension of normal TextView that supports the checkable interface and displays it. CheckedTextView Tutorial With Example In Android Studio
