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?
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"
/>
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With