{"id":1447,"date":"2016-04-19T04:31:37","date_gmt":"2016-04-19T04:31:37","guid":{"rendered":"http:\/\/abhiandroid.com\/ui\/?page_id=1447"},"modified":"2019-06-12T06:50:13","modified_gmt":"2019-06-12T06:50:13","slug":"checkedtextview","status":"publish","type":"page","link":"https:\/\/abhiandroid.com\/ui\/checkedtextview","title":{"rendered":"CheckedTextView Tutorial With Example In Android Studio"},"content":{"rendered":"<p>In Android, CheckedTextView is an extension of normal TextView that supports the checkable interface and displays it. It has a checkbox along with some text. It is mainly used in a ListView where we want to show which item is selected or not. checkmark\u00a0attribute is used to provide a graphic or a drawable to CheckedTextView.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1568\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/CheckedTextView-in-Android.jpg\" alt=\"CheckedTextView in Android\" width=\"348\" height=\"323\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/CheckedTextView-in-Android.jpg 348w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/CheckedTextView-in-Android-300x278.jpg 300w\" sizes=\"auto, (max-width: 348px) 100vw, 348px\" \/><\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important Note:<\/strong><\/span> In \u00a0CheckedTextView we have\u00a0to set\u00a0<code>android:checkMark<\/code> attribute to provide a graphic or drawable otherwise it will not show the check mark and behaves like a normal TextView. Another thing is we can\u2019t change the state of check mark only by clicking on the UI, instead we have to use a listener to do that. We will be explaining all these below.<\/p>\n<p><strong>Basic CheckedTextView code in XML:<\/strong><\/p>\n<p><span style=\"color: #ff0000;\"><strong>Very Important Note:<\/strong><\/span> Before using any\u00a0code on this article make sure to download <a href=\"\/ui\/wp-content\/uploads\/2016\/04\/checked.png\" target=\"_blank\">this image<\/a>\u00a0and save it in your drawable folder named as checked. You can also download the image by click on it below.<\/p>\n<p><a href=\"\/ui\/wp-content\/uploads\/2016\/04\/checked.png\" rel=\"attachment wp-att-1546\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1546\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/checked.png\" alt=\"checked\" width=\"48\" height=\"48\" \/><\/a><\/p>\n<pre>&lt;!--Make sure to download checked image and save in your drawable folder--&gt;\r\n&lt;CheckedTextView\r\nandroid:id=\"@+id\/simpleCheckedTextView\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:checked=\"true\"\r\nandroid:gravity=\"center\"\r\nandroid:checkMark=\"@drawable\/checked\"\r\nandroid:text=\"Checked Text View\" \/&gt;\r\n<\/pre>\n<hr \/>\n<h4><strong>Getting Current State Of CheckedTextView:<\/strong><\/h4>\n<p><span style=\"color: #008000;\"><strong>isChecked(boolean):<\/strong><\/span> This method is used to get the current state of the CheckedTextView. This methods returns a Boolean type value means true or false. It returns true if a CheckedTextView is currently checked and returns false if it is not.<\/p>\n<p>Below is an example code in which we check the current state of the CheckedTextView.<\/p>\n<pre>CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView); \/\/ initiate a CheckedTextView\r\nBoolean checkedValue = simpleCheckedTextView.isChecked(); \/\/ check current state of CheckedTextView<\/pre>\n<hr \/>\n<h4><strong>Attributes of CheckedTextView:<\/strong><\/h4>\n<p>Now let\u2019s \u00a0we discuss some important\u00a0attributes that helps us to configure a CheckedTextView in your xml file.<\/p>\n<p><span style=\"color: #008000;\"><strong>1. id:<\/strong><\/span> This attribute is used to uniquely identify a CheckedTextView.<\/p>\n<p><span style=\"color: #008000;\"><strong>2. checkmark:<\/strong><\/span> This attribute is used to set the drawable for the check mark.<\/p>\n<p><strong>PS:<\/strong> First save the image name as checked in drawable folder before using below code.<\/p>\n<pre>&lt;CheckedTextView\r\nandroid:id=\"@+id\/simpleCheckedTextView\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:checkMark=\"@drawable\/checked\"\r\nandroid:checked=\"true\"\r\nandroid:gravity=\"center\"\r\nandroid:text=\"Android\" \/&gt;&lt;!-- bottom drawable of a CheckedTextView --&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1557\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/checkmark-and-checked-in-CheckedTextView-In-Android.jpg\" alt=\"checkmark and checked in CheckedTextView In Android\" width=\"281\" height=\"191\" \/><\/p>\n<p><strong>Setting checkMark In Java Class:<\/strong><\/p>\n<pre>CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView); \/\/ initiate a CheckedTextView\r\nsimpleCheckedTextView.setCheckMarkDrawable(R.drawable.checked); \/\/ set drawwable for check mark for CheckedTextView<\/pre>\n<p><span style=\"color: #008000;\"><strong>3. checked:<\/strong><\/span> This attribute is used to set the current state of the CheckedTextView. We can also change the state in Java class by using setChecked() method. By default the value of this attribute is false.<\/p>\n<p>In the above code of checkMark we also used this attribute.<\/p>\n<p><strong>Setting checked property\u00a0In Java Class:<\/strong><\/p>\n<p>Use the below code to set the checked property to true programmatically.<\/p>\n<pre>CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView); \/\/ initiate a CheckedTextView\r\nsimpleCheckedTextView.setChecked(true); \/\/ set current state to true for CheckedTextView\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>4. text:<\/strong><\/span> This attribute is used to set the text in a CheckedTextView. We can set the text in xml as well as in the java class.\u00a0In the above code of checkMark we also used text attribute.<\/p>\n<p><strong>Setting text of CheckedTextView In Java class:<\/strong><\/p>\n<pre>CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView); \/\/ initiate a CheckedTextView\r\nsimpleCheckedTextView.setText(\"AbhiAndroid\"); \/\/ set AbhiAndroid text for CheckedTextView<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #008000;\"><strong>5. textColor:<\/strong><\/span> This attribute is used to set the text color of a CheckedTextView. Color value is in the form of &#8220;#argb&#8221;, &#8220;#rgb&#8221;, &#8220;#rrggbb&#8221;, or &#8220;#aarrggbb&#8221;.<\/p>\n<p>Below we set the green color for the displayed text of a CheckedTextView.<\/p>\n<pre>&lt;CheckedTextView\r\nandroid:id=\"@+id\/simpleCheckedTextView\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:checked=\"true\"\r\nandroid:checkMark=\"@drawable\/checked\"\r\nandroid:textColor=\"#0f0\"\r\nandroid:text=\"Android\" \/&gt; &lt;!-- green text\u00a0 color for CheckedTextView --&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1558\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/textColor-in-CheckedTextView-Android.jpg\" alt=\"textColor in CheckedTextView Android\" width=\"339\" height=\"199\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/textColor-in-CheckedTextView-Android.jpg 339w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/textColor-in-CheckedTextView-Android-300x176.jpg 300w\" sizes=\"auto, (max-width: 339px) 100vw, 339px\" \/><\/p>\n<p><strong>Setting textColor Of CheckTextView Text In Java class:<\/strong><\/p>\n<pre>CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView); \/\/ initiate a CheckedTextView\r\nsimpleCheckedTextView.setTextColor(Color.GREEN); \/\/ set green text color for CheckedTextView\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>6. textSize:<\/strong><\/span> This attribute is used to set the size of text of a CheckedTextView. We can set the text size in sp(scale independent pixel) or in dp(density pixel).<\/p>\n<p>Below we set the 20 sp size for the text of a CheckedTextView.<\/p>\n<pre>&lt;CheckedTextView\r\nandroid:id=\"@+id\/simpleCheckedTextView\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:checked=\"true\"\r\nandroid:gravity=\"center\"\r\nandroid:checkMark=\"@drawable\/checked\"\r\nandroid:textColor=\"#0f0\"\r\nandroid:textSize=\"20sp\"\r\nandroid:text=\"Android\" \/&gt; &lt;!-- 20 sp displayed text Size of a CheckedTextView --&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1559\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/textSize-in-CheckedTextView-Android.jpg\" alt=\"textSize in CheckedTextView Android\" width=\"337\" height=\"220\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/textSize-in-CheckedTextView-Android.jpg 337w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/textSize-in-CheckedTextView-Android-300x196.jpg 300w\" sizes=\"auto, (max-width: 337px) 100vw, 337px\" \/><\/p>\n<p><strong>Setting text Size of CheckedTextView Text In Java class:<\/strong><\/p>\n<pre>CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView); \/\/ initiate a CheckedTextView\r\nsimpleCheckedTextView.setTextSize(20); \/\/ set text size for CheckedTextView\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>7. textStyle:<\/strong><\/span> This attribute is used to set the style for the text of a CheckedTextView. The possible text styles are bold, italic and normal. If we need to use two or more styles for a text view then \u201c|\u201d operator is used for that.<\/p>\n<p>Below we set the bold and italic text styles for the text of CheckedTextView.<\/p>\n<pre>&lt;CheckedTextView\r\nandroid:id=\"@+id\/simpleCheckedTextView\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:checked=\"true\"\r\nandroid:checkMark=\"@drawable\/checked\"\r\nandroid:textSize=\"20sp\"\r\nandroid:text=\"Android\"\r\nandroid:textStyle=\"bold|italic\"\/&gt; &lt;!-- bold and italic text style for a CheckedTextView --&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1560\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/textStyle-in-CheckedTextView-Android.jpg\" alt=\"textStyle in CheckedTextView Android\" width=\"338\" height=\"228\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/textStyle-in-CheckedTextView-Android.jpg 338w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/textStyle-in-CheckedTextView-Android-300x202.jpg 300w\" sizes=\"auto, (max-width: 338px) 100vw, 338px\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>8. background:<\/strong><\/span> This attribute is used to set the background of a CheckedTextView. We can set a color or a drawable in the background of a CheckedTextView.<\/p>\n<p>Below we set the black color for the background, white color for the displayed text of a CheckedTextView.<\/p>\n<pre>&lt;CheckedTextView\r\nandroid:id=\"@+id\/simpleCheckedTextView\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:checked=\"true\"\r\nandroid:checkMark=\"@drawable\/checked\"\r\nandroid:textColor=\"#fff\"\r\nandroid:background=\"#000\"\r\nandroid:textSize=\"20sp\"\r\nandroid:text=\"AbhiAndroid\"\r\nandroid:textStyle=\"bold|italic\"\/&gt; &lt;!-- black background of a CheckedTextView --&gt;\r\n<\/pre>\n<p><strong>Setting Background of CheckedTextView In Java class:<\/strong><\/p>\n<pre>CheckedTextView simpleCheckedTextView = (CheckedTextView) findViewById(R.id.simpleCheckedTextView); \/\/ initiate a CheckedTextView\r\nsimpleCheckedTextView.setBackgroundColor(Color.BLACK); \/\/ set black background for CheckedTextView\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1561\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/background-in-CheckedTextView-Android.jpg\" alt=\"background in CheckedTextView Android\" width=\"339\" height=\"231\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/background-in-CheckedTextView-Android.jpg 339w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/background-in-CheckedTextView-Android-300x204.jpg 300w\" sizes=\"auto, (max-width: 339px) 100vw, 339px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #008000;\"><strong>9. drawableBottom, drawableTop, drawableRight And drawableLeft<\/strong><\/span><strong><span style=\"color: #008000;\">:<\/span>\u00a0<\/strong>These attribute draw the drawable below, top, right and left of the text of CheckedTextView.<\/p>\n<p>Below we save the\u00a0ic_launcher image in drawable folder and then use it to set as drawableLeft. In the similar way you can try for other three attribute yourself.<\/p>\n<pre>&lt;CheckedTextView\r\n    android:id=\"@+id\/simpleCheckedTextView\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"wrap_content\"\r\n    android:checked=\"true\"\r\n    android:gravity=\"center\"\r\n    android:checkMark=\"@drawable\/checked\"\r\n    android:textColor=\"#fff\"\r\n    android:background=\"#000\"\r\n    android:textSize=\"20sp\"\r\n    android:text=\"Android\"\r\n    android:drawableLeft=\"@drawable\/ic_launcher\"\r\n    android:textStyle=\"bold|italic\"\/&gt; &lt;!-- bottom drawable of a CheckedTextView --&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1562\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/drawableLeft-in-CheckedTextView-Android.jpg\" alt=\"drawableLeft in CheckedTextView Android\" width=\"340\" height=\"266\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/drawableLeft-in-CheckedTextView-Android.jpg 340w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/drawableLeft-in-CheckedTextView-Android-300x235.jpg 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/p>\n<hr \/>\n<h4><strong>CheckedTextView Example In Android Studio<\/strong><\/h4>\n<p><span style=\"color: #008000;\"><strong>EXAMPLE 1:\u00a0CHECKEDTEXTVIEW WITH LISTVIEW EXAMPLE IN ANDROID STUDIO<\/strong><\/span><\/p>\n<p>Below is the example of CheckedTextView in which we display a list of Superstar names in CheckedTexView by using BaseAdapter. In this we change the current state of the CheckedTextView on click event. Whenever a user clicks on this CheckedTextView the current state is changed and checked or unchecked value is displayed by using a Toast.<\/p>\n<p>Below you can download complete Android Studio project code, final output and step by step explanation:<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"https:\/\/github.com\/abhisheksaini4\/CheckedTextViewExample\" target=\"_blank\" rel=\"nofollow\">Download Code<\/a><a class=\"help\" title=\"Learn How To Download Code And Import In Android Studio\" href=\"\/androidstudio\/download-code-abhiandroid\" target=\"_blank\" rel=\"nofollow\"> ? <\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1565\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/CHECKEDTEXTVIEW-WITH-LISTVIEW-EXAMPLE-IN-ANDROID-STUDIO.gif\" alt=\"CHECKEDTEXTVIEW WITH LISTVIEW EXAMPLE IN ANDROID STUDIO\" width=\"305\" height=\"451\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>Step 1<\/strong><\/span><strong><span style=\"color: #008000;\">:<\/span>\u00a0<\/strong>Create a new project and name it CheckedTextViewExample<\/p>\n<p><span style=\"color: #008000;\"><strong>Step 2:<\/strong><\/span><strong>\u00a0<\/strong>Open res -&gt; layout -&gt;activity_main.xml (or) main.xml and add following code for displaying a ListView:<\/p>\n<pre>&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\nxmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\nandroid:layout_width=\"match_parent\"\r\nandroid:layout_height=\"match_parent\"\r\ntools:context=\".MainActivity\"&gt;\r\n\r\n&lt;ListView\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"fill_parent\"\r\nandroid:id=\"@+id\/listView\"\/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 3:<\/strong><\/span>\u00a0Create a new xml list_items.xml inside layout and add the below code for displaying a CheckedTextView by using its different Attributes:<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\nandroid:layout_width=\"match_parent\"\r\nandroid:layout_height=\"match_parent\"\r\nandroid:orientation=\"vertical\"&gt;\r\n\r\n&lt;CheckedTextView\r\nandroid:id=\"@+id\/simpleCheckedTextView\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"50dp\"\r\nandroid:checked=\"false\"\r\nandroid:gravity=\"center_vertical\"\r\nandroid:paddingLeft=\"15dp\"\r\nandroid:textColor=\"#000\"\r\nandroid:text=\"Checked Text View Example\" \/&gt;\r\n&lt;!-- CheckedTextView In Android --&gt;\r\n&lt;\/LinearLayout&gt;\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 4:<\/strong><\/span><strong>\u00a0<\/strong>Open src -&gt; package -&gt; MainActivity.java<\/p>\n<p>In this step we add the code for initiate the <em>ListView <\/em>and then set the adapter to fill the data in the ListView from a String Array.<\/p>\n<pre>package example.abhiandroid.checkedtextviewexample;\r\n\r\nimport android.os.Bundle;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.view.Menu;\r\nimport android.view.MenuItem;\r\nimport android.widget.ListView;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    String value;\r\n    String[] superStarNames = {\"John Cena\", \"Randy Orton\", \"Triple H\", \"Roman Reign\", \"Sheamus\"};\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        \/\/ initiate a ListView\r\n        ListView listView = (ListView) findViewById(R.id.listView);\r\n        \/\/ set the adapter to fill the data in ListView\r\n        CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), superStarNames);\r\n        listView.setAdapter(customAdapter);\r\n    }\r\n\r\n    \r\n}<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 5:<\/strong><\/span>\u00a0Create a new class CustomAdapter.java inside package and add the following code<\/p>\n<p>In this we extend BaseAdapter to fill the data in the ListView and then perform click event on list items. Whenever a user clicks on the CheckedTextView the current state is changed and checked or unchecked value is displayed by using a Toast.<\/p>\n<pre>package example.abhiandroid.checkedtextviewexample;\r\n\r\nimport android.content.Context;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.widget.BaseAdapter;\r\nimport android.widget.CheckedTextView;\r\nimport android.widget.Toast;\r\n\r\npublic class CustomAdapter extends BaseAdapter {\r\nString[] names;\r\nContext context;\r\nLayoutInflater inflter;\r\nString value;\r\n\r\npublic CustomAdapter(Context context, String[] names) {\r\nthis.context = context;\r\nthis.names = names;\r\ninflter = (LayoutInflater.from(context));\r\n\r\n}\r\n\r\n@Override\r\npublic int getCount() {\r\nreturn names.length;\r\n}\r\n\r\n@Override\r\npublic Object getItem(int position) {\r\nreturn null;\r\n}\r\n\r\n@Override\r\npublic long getItemId(int position) {\r\nreturn 0;\r\n}\r\n\r\n@Override\r\npublic View getView(int position, View view, ViewGroup parent) {\r\nview = inflter.inflate(R.layout.list_view_items, null);\r\nfinal CheckedTextView simpleCheckedTextView = (CheckedTextView) view.findViewById(R.id.simpleCheckedTextView);\r\nsimpleCheckedTextView.setText(names[position]);\r\n\/\/ perform on Click Event Listener on CheckedTextView\r\nsimpleCheckedTextView.setOnClickListener(new View.OnClickListener() {\r\n@Override\r\npublic void onClick(View v) {\r\nif (simpleCheckedTextView.isChecked()) {\r\n\/\/ set cheek mark drawable and set checked property to false\r\nvalue = \"un-Checked\";\r\nsimpleCheckedTextView.setCheckMarkDrawable(0);\r\nsimpleCheckedTextView.setChecked(false);\r\n} else {\r\n\/\/ set cheek mark drawable and set checked property to true\r\nvalue = \"Checked\";\r\nsimpleCheckedTextView.setCheckMarkDrawable(R.drawable.checked);\r\nsimpleCheckedTextView.setChecked(true);\r\n}\r\nToast.makeText(context, value, Toast.LENGTH_SHORT).show();\r\n}\r\n});\r\nreturn view;\r\n}\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Now run the App and you will see WWE Superstar names listed in ListView. Now click on any Superstar and you will notice checkbox will appear on the right side. When you re-click on the same selected name, the checkbox will dis-appear.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Android, CheckedTextView is an extension of normal TextView that supports the checkable interface and displays it. It has a checkbox along with some text. It is mainly used in a ListView where we want to show which item is selected or not. checkmark\u00a0attribute is used to provide a graphic or a drawable to CheckedTextView. &hellip; <a href=\"https:\/\/abhiandroid.com\/ui\/checkedtextview\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">CheckedTextView Tutorial With Example In Android Studio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"home.php","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-1447","page","type-page","status-publish","hentry"],"acf":[],"psp_head":"<title>CheckedTextView Tutorial With Example In Android Studio \u2013 Abhi Android<\/title>\r\n<meta name=\"description\" content=\"Learn CheckedTextView which is mostly used with ListView to show checkable interface with example in Android Studio. It has a checkbox along with some text.\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/ui\/checkedtextview\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/comments?post=1447"}],"version-history":[{"count":3,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1447\/revisions"}],"predecessor-version":[{"id":2780,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1447\/revisions\/2780"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/media?parent=1447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}