Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make the Checkbox in Android CheckedTextView be left aligned instead of right aligned?

Tags:

android

I am trying to use R.layout.simple_list_item_multiple_choice with ListView. CheckedTextView is used in simple_list_item_multiple_choice.xml, but how can I make the checkbox be left aligned instead of right aligned?

like image 734
Kevin W Avatar asked Jun 25 '10 00:06

Kevin W


3 Answers

The secret is in android:checkMark make it null

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/checked_text_single_choice"
android:layout_width="match_parent"
android:layout_height="52dp"
android:checkMark="@null"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall" 
android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
android:drawableRight="@null"
android:textColor="@android:color/black"
/>
like image 178
Mohammed Elsabry Avatar answered Nov 09 '22 06:11

Mohammed Elsabry


Create your own row template and set android:drawableLeft on the CheckedTextView.

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"
/>

or

android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
like image 20
Roger Keays Avatar answered Nov 09 '22 05:11

Roger Keays


If you want the checkbox to be on the left, simply just use a CheckBox. Maybe it is not matter of course, but a CheckBox can contain text. You can define that text by adding an XML attribute android:text, or by calling the setText() method. Actually CheckBox is inherited from Button, which inherits from TextView, that's why it has all the text-related properties.

like image 11
WonderCsabo Avatar answered Nov 09 '22 04:11

WonderCsabo