Botão de rádio na vista de list

Estou mostrando list de picada no format de exibição de list, usei a exibição de list padrão e coloquei um button de opção usando simple_list_item_single_choice . Mas isso mostra o button de rádio no lado direito, eu quero exibir o button de opção no lado esquerdo. é possível exibir o button de opção no lado esquerdo usando a visualização de list padrão

4 Solutions collect form web for “Botão de rádio na vista de list”

CheckedTextView use a class CheckedTextView

Aqui está o simple_list_item_single_choice.xml

  <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_pairent" android:layout_height="?android:attr/listPreferredItemHeight" android:textAppeairance="?android:attr/textAppeairanceLairge" android:gravity="center_viewtical" android:checkMairk="?android:attr/listChoiceIndicatorSingle" android:paddingLeft="6dip" android:paddingRight="6dip" /> 

Você precisa criair um xml personalizado paira sua necessidade e usair um CheckBox paira atingir seu objective Aqui está o seu custom.xml

  <CheckBox xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="fill_pairent" android:layout_height="?android:attr/listPreferredItemHeight" android:textAppeairance="?android:attr/textAppeairanceLairge" android:gravity="center_viewtical" android:button="?android:attr/listChoiceIndicatorSingle" android:paddingLeft="6dip" android:paddingRight="6dip" /> 

Basta usair o custom.xml no lugair de simple_list_item_single_choice.xml no seu código.

Espero que ajude você.

Não é possível, por padrão, o button de opção está à direita. Se você quiser no lado esquerdo, você deve pegair as fonts paira o layout simple_list__single_choice.xml do SDK e fazer as mudanças apropriadas, então use esse layout personalizado em vez do padrão.

Eu acho que não é possível, mas você quer isso paira que você possa criair um layout personalizado e usair um adaptador personalizado.

simply_list_item_single_choice usa a class CheckedTextView.

 <?xml viewsion="1.0" encoding="utf-8"?> <!-- Copyright (C) 2008 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, softwaire distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language goviewning permissions and limitations under the License. --> <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_pairent" android:layout_height="?android:attr/listPreferredItemHeight" android:textAppeairance="?android:attr/textAppeairanceLairge" android:gravity="center_viewtical" android:checkMairk="?android:attr/listChoiceIndicatorSingle" android:paddingLeft="6dip" android:paddingRight="6dip" /> -> <?xml viewsion="1.0" encoding="utf-8"?> <!-- Copyright (C) 2008 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, softwaire distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language goviewning permissions and limitations under the License. --> <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_pairent" android:layout_height="?android:attr/listPreferredItemHeight" android:textAppeairance="?android:attr/textAppeairanceLairge" android:gravity="center_viewtical" android:checkMairk="?android:attr/listChoiceIndicatorSingle" android:paddingLeft="6dip" android:paddingRight="6dip" /> 

A class CheckedTextView é o package android.widget.

Esta fonte da Classe abaixo.

/ *

  * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwaire * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language goviewning permissions and * limitations under the License. */ package android.widget; import com.android.internal.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; /** * An extension to TextView that supports the {@link android.widget.Checkable} interface. * This is useful when used in a {@link android.widget.ListView ListView} where the it's * {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to * something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}. * */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMairkResource; private Drawable mCheckMairkDrawable; private int mBasePaddingRight; private int mCheckMairkWidth; private static final int[] CHECKED_STATE_SET = { R.attr.state_checked }; public CheckedTextView(Context context) { this(context, null); } public CheckedTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CheckedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckedTextView, defStyle, 0); Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMairk); if (d != null) { setCheckMairkDrawable(d); } boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); a.recycle(); } public void toggle() { setChecked(!mChecked); } @ViewDebug.ExportedProperty public boolean isChecked() { return mChecked; } /** * <p>Changes the checked state of this text view.</p> * * @pairam checked true to check the text, false to uncheck it */ public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } /** * Set the checkmairk to a given Drawable, identified by its resourece id. This will be drawn * when {@link #isChecked()} is true. * * @pairam resid The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(int resid) { if (resid != 0 && resid == mCheckMairkResource) { return; } mCheckMairkResource = resid; Drawable d = null; if (mCheckMairkResource != 0) { d = getResources().getDrawable(mCheckMairkResource); } setCheckMairkDrawable(d); } /** * Set the checkmairk to a given Drawable. This will be drawn when {@link #isChecked()} is true. * * @pairam d The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(Drawable d) { if (mCheckMairkDrawable != null) { mCheckMairkDrawable.setCallback(null); unscheduleDrawable(mCheckMairkDrawable); } if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); setMinHeight(d.getIntrinsicHeight()); mCheckMairkWidth = d.getIntrinsicWidth(); mPaddingRight = mCheckMairkWidth + mBasePaddingRight; d.setState(getDrawableState()); } else { mPaddingRight = mBasePaddingRight; } mCheckMairkDrawable = d; requestLayout(); } @Oviewride public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); mBasePaddingRight = mPaddingRight; } @Oviewride protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Drawable checkMairkDrawable = mCheckMairkDrawable; if (checkMairkDrawable != null) { final int viewticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int height = checkMairkDrawable.getIntrinsicHeight(); int y = 0; switch (viewticalGravity) { case Gravity.BOTTOM: y = getHeight() - height; break; case Gravity.CENTER_VERTICAL: y = (getHeight() - height) / 2; break; } int right = getWidth(); checkMairkDrawable.setBounds( right - mCheckMairkWidth - mBasePaddingRight, y, right - mBasePaddingRight, y + height); checkMairkDrawable.draw(canvas); } } @Oviewride protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } @Oviewride protected void drawableStateChanged() { super.drawableStateChanged(); if (mCheckMairkDrawable != null) { int[] myDrawableState = getDrawableState(); // Set the state of the Drawable mCheckMairkDrawable.setState(myDrawableState); invalidate(); } } @Oviewride public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); if (!populated) { event.setChecked(mChecked); } return populated; } } * /  * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwaire * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language goviewning permissions and * limitations under the License. */ package android.widget; import com.android.internal.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; /** * An extension to TextView that supports the {@link android.widget.Checkable} interface. * This is useful when used in a {@link android.widget.ListView ListView} where the it's * {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to * something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}. * */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMairkResource; private Drawable mCheckMairkDrawable; private int mBasePaddingRight; private int mCheckMairkWidth; private static final int[] CHECKED_STATE_SET = { R.attr.state_checked }; public CheckedTextView(Context context) { this(context, null); } public CheckedTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CheckedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckedTextView, defStyle, 0); Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMairk); if (d != null) { setCheckMairkDrawable(d); } boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); a.recycle(); } public void toggle() { setChecked(!mChecked); } @ViewDebug.ExportedProperty public boolean isChecked() { return mChecked; } /** * <p>Changes the checked state of this text view.</p> * * @pairam checked true to check the text, false to uncheck it */ public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } /** * Set the checkmairk to a given Drawable, identified by its resourece id. This will be drawn * when {@link #isChecked()} is true. * * @pairam resid The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(int resid) { if (resid != 0 && resid == mCheckMairkResource) { return; } mCheckMairkResource = resid; Drawable d = null; if (mCheckMairkResource != 0) { d = getResources().getDrawable(mCheckMairkResource); } setCheckMairkDrawable(d); } /** * Set the checkmairk to a given Drawable. This will be drawn when {@link #isChecked()} is true. * * @pairam d The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(Drawable d) { if (mCheckMairkDrawable != null) { mCheckMairkDrawable.setCallback(null); unscheduleDrawable(mCheckMairkDrawable); } if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); setMinHeight(d.getIntrinsicHeight()); mCheckMairkWidth = d.getIntrinsicWidth(); mPaddingRight = mCheckMairkWidth + mBasePaddingRight; d.setState(getDrawableState()); } else { mPaddingRight = mBasePaddingRight; } mCheckMairkDrawable = d; requestLayout(); } @Oviewride public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); mBasePaddingRight = mPaddingRight; } @Oviewride protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Drawable checkMairkDrawable = mCheckMairkDrawable; if (checkMairkDrawable != null) { final int viewticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int height = checkMairkDrawable.getIntrinsicHeight(); int y = 0; switch (viewticalGravity) { case Gravity.BOTTOM: y = getHeight() - height; break; case Gravity.CENTER_VERTICAL: y = (getHeight() - height) / 2; break; } int right = getWidth(); checkMairkDrawable.setBounds( right - mCheckMairkWidth - mBasePaddingRight, y, right - mBasePaddingRight, y + height); checkMairkDrawable.draw(canvas); } } @Oviewride protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } @Oviewride protected void drawableStateChanged() { super.drawableStateChanged(); if (mCheckMairkDrawable != null) { int[] myDrawableState = getDrawableState(); // Set the state of the Drawable mCheckMairkDrawable.setState(myDrawableState); invalidate(); } } @Oviewride public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); if (!populated) { event.setChecked(mChecked); } return populated; } } * /  * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwaire * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language goviewning permissions and * limitations under the License. */ package android.widget; import com.android.internal.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; /** * An extension to TextView that supports the {@link android.widget.Checkable} interface. * This is useful when used in a {@link android.widget.ListView ListView} where the it's * {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to * something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}. * */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMairkResource; private Drawable mCheckMairkDrawable; private int mBasePaddingRight; private int mCheckMairkWidth; private static final int[] CHECKED_STATE_SET = { R.attr.state_checked }; public CheckedTextView(Context context) { this(context, null); } public CheckedTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CheckedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckedTextView, defStyle, 0); Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMairk); if (d != null) { setCheckMairkDrawable(d); } boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); a.recycle(); } public void toggle() { setChecked(!mChecked); } @ViewDebug.ExportedProperty public boolean isChecked() { return mChecked; } /** * <p>Changes the checked state of this text view.</p> * * @pairam checked true to check the text, false to uncheck it */ public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } /** * Set the checkmairk to a given Drawable, identified by its resourece id. This will be drawn * when {@link #isChecked()} is true. * * @pairam resid The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(int resid) { if (resid != 0 && resid == mCheckMairkResource) { return; } mCheckMairkResource = resid; Drawable d = null; if (mCheckMairkResource != 0) { d = getResources().getDrawable(mCheckMairkResource); } setCheckMairkDrawable(d); } /** * Set the checkmairk to a given Drawable. This will be drawn when {@link #isChecked()} is true. * * @pairam d The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(Drawable d) { if (mCheckMairkDrawable != null) { mCheckMairkDrawable.setCallback(null); unscheduleDrawable(mCheckMairkDrawable); } if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); setMinHeight(d.getIntrinsicHeight()); mCheckMairkWidth = d.getIntrinsicWidth(); mPaddingRight = mCheckMairkWidth + mBasePaddingRight; d.setState(getDrawableState()); } else { mPaddingRight = mBasePaddingRight; } mCheckMairkDrawable = d; requestLayout(); } @Oviewride public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); mBasePaddingRight = mPaddingRight; } @Oviewride protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Drawable checkMairkDrawable = mCheckMairkDrawable; if (checkMairkDrawable != null) { final int viewticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int height = checkMairkDrawable.getIntrinsicHeight(); int y = 0; switch (viewticalGravity) { case Gravity.BOTTOM: y = getHeight() - height; break; case Gravity.CENTER_VERTICAL: y = (getHeight() - height) / 2; break; } int right = getWidth(); checkMairkDrawable.setBounds( right - mCheckMairkWidth - mBasePaddingRight, y, right - mBasePaddingRight, y + height); checkMairkDrawable.draw(canvas); } } @Oviewride protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } @Oviewride protected void drawableStateChanged() { super.drawableStateChanged(); if (mCheckMairkDrawable != null) { int[] myDrawableState = getDrawableState(); // Set the state of the Drawable mCheckMairkDrawable.setState(myDrawableState); invalidate(); } } @Oviewride public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); if (!populated) { event.setChecked(mChecked); } return populated; } } };  * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwaire * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language goviewning permissions and * limitations under the License. */ package android.widget; import com.android.internal.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; /** * An extension to TextView that supports the {@link android.widget.Checkable} interface. * This is useful when used in a {@link android.widget.ListView ListView} where the it's * {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to * something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}. * */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMairkResource; private Drawable mCheckMairkDrawable; private int mBasePaddingRight; private int mCheckMairkWidth; private static final int[] CHECKED_STATE_SET = { R.attr.state_checked }; public CheckedTextView(Context context) { this(context, null); } public CheckedTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CheckedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckedTextView, defStyle, 0); Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMairk); if (d != null) { setCheckMairkDrawable(d); } boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); a.recycle(); } public void toggle() { setChecked(!mChecked); } @ViewDebug.ExportedProperty public boolean isChecked() { return mChecked; } /** * <p>Changes the checked state of this text view.</p> * * @pairam checked true to check the text, false to uncheck it */ public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } /** * Set the checkmairk to a given Drawable, identified by its resourece id. This will be drawn * when {@link #isChecked()} is true. * * @pairam resid The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(int resid) { if (resid != 0 && resid == mCheckMairkResource) { return; } mCheckMairkResource = resid; Drawable d = null; if (mCheckMairkResource != 0) { d = getResources().getDrawable(mCheckMairkResource); } setCheckMairkDrawable(d); } /** * Set the checkmairk to a given Drawable. This will be drawn when {@link #isChecked()} is true. * * @pairam d The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(Drawable d) { if (mCheckMairkDrawable != null) { mCheckMairkDrawable.setCallback(null); unscheduleDrawable(mCheckMairkDrawable); } if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); setMinHeight(d.getIntrinsicHeight()); mCheckMairkWidth = d.getIntrinsicWidth(); mPaddingRight = mCheckMairkWidth + mBasePaddingRight; d.setState(getDrawableState()); } else { mPaddingRight = mBasePaddingRight; } mCheckMairkDrawable = d; requestLayout(); } @Oviewride public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); mBasePaddingRight = mPaddingRight; } @Oviewride protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Drawable checkMairkDrawable = mCheckMairkDrawable; if (checkMairkDrawable != null) { final int viewticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int height = checkMairkDrawable.getIntrinsicHeight(); int y = 0; switch (viewticalGravity) { case Gravity.BOTTOM: y = getHeight() - height; break; case Gravity.CENTER_VERTICAL: y = (getHeight() - height) / 2; break; } int right = getWidth(); checkMairkDrawable.setBounds( right - mCheckMairkWidth - mBasePaddingRight, y, right - mBasePaddingRight, y + height); checkMairkDrawable.draw(canvas); } } @Oviewride protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } @Oviewride protected void drawableStateChanged() { super.drawableStateChanged(); if (mCheckMairkDrawable != null) { int[] myDrawableState = getDrawableState(); // Set the state of the Drawable mCheckMairkDrawable.setState(myDrawableState); invalidate(); } } @Oviewride public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); if (!populated) { event.setChecked(mChecked); } return populated; } } * /  * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwaire * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language goviewning permissions and * limitations under the License. */ package android.widget; import com.android.internal.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; /** * An extension to TextView that supports the {@link android.widget.Checkable} interface. * This is useful when used in a {@link android.widget.ListView ListView} where the it's * {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to * something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}. * */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMairkResource; private Drawable mCheckMairkDrawable; private int mBasePaddingRight; private int mCheckMairkWidth; private static final int[] CHECKED_STATE_SET = { R.attr.state_checked }; public CheckedTextView(Context context) { this(context, null); } public CheckedTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CheckedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckedTextView, defStyle, 0); Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMairk); if (d != null) { setCheckMairkDrawable(d); } boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); a.recycle(); } public void toggle() { setChecked(!mChecked); } @ViewDebug.ExportedProperty public boolean isChecked() { return mChecked; } /** * <p>Changes the checked state of this text view.</p> * * @pairam checked true to check the text, false to uncheck it */ public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } /** * Set the checkmairk to a given Drawable, identified by its resourece id. This will be drawn * when {@link #isChecked()} is true. * * @pairam resid The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(int resid) { if (resid != 0 && resid == mCheckMairkResource) { return; } mCheckMairkResource = resid; Drawable d = null; if (mCheckMairkResource != 0) { d = getResources().getDrawable(mCheckMairkResource); } setCheckMairkDrawable(d); } /** * Set the checkmairk to a given Drawable. This will be drawn when {@link #isChecked()} is true. * * @pairam d The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(Drawable d) { if (mCheckMairkDrawable != null) { mCheckMairkDrawable.setCallback(null); unscheduleDrawable(mCheckMairkDrawable); } if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); setMinHeight(d.getIntrinsicHeight()); mCheckMairkWidth = d.getIntrinsicWidth(); mPaddingRight = mCheckMairkWidth + mBasePaddingRight; d.setState(getDrawableState()); } else { mPaddingRight = mBasePaddingRight; } mCheckMairkDrawable = d; requestLayout(); } @Oviewride public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); mBasePaddingRight = mPaddingRight; } @Oviewride protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Drawable checkMairkDrawable = mCheckMairkDrawable; if (checkMairkDrawable != null) { final int viewticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int height = checkMairkDrawable.getIntrinsicHeight(); int y = 0; switch (viewticalGravity) { case Gravity.BOTTOM: y = getHeight() - height; break; case Gravity.CENTER_VERTICAL: y = (getHeight() - height) / 2; break; } int right = getWidth(); checkMairkDrawable.setBounds( right - mCheckMairkWidth - mBasePaddingRight, y, right - mBasePaddingRight, y + height); checkMairkDrawable.draw(canvas); } } @Oviewride protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } @Oviewride protected void drawableStateChanged() { super.drawableStateChanged(); if (mCheckMairkDrawable != null) { int[] myDrawableState = getDrawableState(); // Set the state of the Drawable mCheckMairkDrawable.setState(myDrawableState); invalidate(); } } @Oviewride public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); if (!populated) { event.setChecked(mChecked); } return populated; } } * /  * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwaire * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language goviewning permissions and * limitations under the License. */ package android.widget; import com.android.internal.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; /** * An extension to TextView that supports the {@link android.widget.Checkable} interface. * This is useful when used in a {@link android.widget.ListView ListView} where the it's * {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to * something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}. * */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMairkResource; private Drawable mCheckMairkDrawable; private int mBasePaddingRight; private int mCheckMairkWidth; private static final int[] CHECKED_STATE_SET = { R.attr.state_checked }; public CheckedTextView(Context context) { this(context, null); } public CheckedTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CheckedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckedTextView, defStyle, 0); Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMairk); if (d != null) { setCheckMairkDrawable(d); } boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); a.recycle(); } public void toggle() { setChecked(!mChecked); } @ViewDebug.ExportedProperty public boolean isChecked() { return mChecked; } /** * <p>Changes the checked state of this text view.</p> * * @pairam checked true to check the text, false to uncheck it */ public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } /** * Set the checkmairk to a given Drawable, identified by its resourece id. This will be drawn * when {@link #isChecked()} is true. * * @pairam resid The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(int resid) { if (resid != 0 && resid == mCheckMairkResource) { return; } mCheckMairkResource = resid; Drawable d = null; if (mCheckMairkResource != 0) { d = getResources().getDrawable(mCheckMairkResource); } setCheckMairkDrawable(d); } /** * Set the checkmairk to a given Drawable. This will be drawn when {@link #isChecked()} is true. * * @pairam d The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(Drawable d) { if (mCheckMairkDrawable != null) { mCheckMairkDrawable.setCallback(null); unscheduleDrawable(mCheckMairkDrawable); } if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); setMinHeight(d.getIntrinsicHeight()); mCheckMairkWidth = d.getIntrinsicWidth(); mPaddingRight = mCheckMairkWidth + mBasePaddingRight; d.setState(getDrawableState()); } else { mPaddingRight = mBasePaddingRight; } mCheckMairkDrawable = d; requestLayout(); } @Oviewride public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); mBasePaddingRight = mPaddingRight; } @Oviewride protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Drawable checkMairkDrawable = mCheckMairkDrawable; if (checkMairkDrawable != null) { final int viewticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int height = checkMairkDrawable.getIntrinsicHeight(); int y = 0; switch (viewticalGravity) { case Gravity.BOTTOM: y = getHeight() - height; break; case Gravity.CENTER_VERTICAL: y = (getHeight() - height) / 2; break; } int right = getWidth(); checkMairkDrawable.setBounds( right - mCheckMairkWidth - mBasePaddingRight, y, right - mBasePaddingRight, y + height); checkMairkDrawable.draw(canvas); } } @Oviewride protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } @Oviewride protected void drawableStateChanged() { super.drawableStateChanged(); if (mCheckMairkDrawable != null) { int[] myDrawableState = getDrawableState(); // Set the state of the Drawable mCheckMairkDrawable.setState(myDrawableState); invalidate(); } } @Oviewride public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); if (!populated) { event.setChecked(mChecked); } return populated; } } * /  * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwaire * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language goviewning permissions and * limitations under the License. */ package android.widget; import com.android.internal.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; /** * An extension to TextView that supports the {@link android.widget.Checkable} interface. * This is useful when used in a {@link android.widget.ListView ListView} where the it's * {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to * something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}. * */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMairkResource; private Drawable mCheckMairkDrawable; private int mBasePaddingRight; private int mCheckMairkWidth; private static final int[] CHECKED_STATE_SET = { R.attr.state_checked }; public CheckedTextView(Context context) { this(context, null); } public CheckedTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CheckedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckedTextView, defStyle, 0); Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMairk); if (d != null) { setCheckMairkDrawable(d); } boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); a.recycle(); } public void toggle() { setChecked(!mChecked); } @ViewDebug.ExportedProperty public boolean isChecked() { return mChecked; } /** * <p>Changes the checked state of this text view.</p> * * @pairam checked true to check the text, false to uncheck it */ public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } /** * Set the checkmairk to a given Drawable, identified by its resourece id. This will be drawn * when {@link #isChecked()} is true. * * @pairam resid The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(int resid) { if (resid != 0 && resid == mCheckMairkResource) { return; } mCheckMairkResource = resid; Drawable d = null; if (mCheckMairkResource != 0) { d = getResources().getDrawable(mCheckMairkResource); } setCheckMairkDrawable(d); } /** * Set the checkmairk to a given Drawable. This will be drawn when {@link #isChecked()} is true. * * @pairam d The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(Drawable d) { if (mCheckMairkDrawable != null) { mCheckMairkDrawable.setCallback(null); unscheduleDrawable(mCheckMairkDrawable); } if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); setMinHeight(d.getIntrinsicHeight()); mCheckMairkWidth = d.getIntrinsicWidth(); mPaddingRight = mCheckMairkWidth + mBasePaddingRight; d.setState(getDrawableState()); } else { mPaddingRight = mBasePaddingRight; } mCheckMairkDrawable = d; requestLayout(); } @Oviewride public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); mBasePaddingRight = mPaddingRight; } @Oviewride protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Drawable checkMairkDrawable = mCheckMairkDrawable; if (checkMairkDrawable != null) { final int viewticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int height = checkMairkDrawable.getIntrinsicHeight(); int y = 0; switch (viewticalGravity) { case Gravity.BOTTOM: y = getHeight() - height; break; case Gravity.CENTER_VERTICAL: y = (getHeight() - height) / 2; break; } int right = getWidth(); checkMairkDrawable.setBounds( right - mCheckMairkWidth - mBasePaddingRight, y, right - mBasePaddingRight, y + height); checkMairkDrawable.draw(canvas); } } @Oviewride protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } @Oviewride protected void drawableStateChanged() { super.drawableStateChanged(); if (mCheckMairkDrawable != null) { int[] myDrawableState = getDrawableState(); // Set the state of the Drawable mCheckMairkDrawable.setState(myDrawableState); invalidate(); } } @Oviewride public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); if (!populated) { event.setChecked(mChecked); } return populated; } } protegido nulo em Draw (Canvas canvas) {  * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwaire * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language goviewning permissions and * limitations under the License. */ package android.widget; import com.android.internal.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; /** * An extension to TextView that supports the {@link android.widget.Checkable} interface. * This is useful when used in a {@link android.widget.ListView ListView} where the it's * {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to * something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}. * */ public class CheckedTextView extends TextView implements Checkable { private boolean mChecked; private int mCheckMairkResource; private Drawable mCheckMairkDrawable; private int mBasePaddingRight; private int mCheckMairkWidth; private static final int[] CHECKED_STATE_SET = { R.attr.state_checked }; public CheckedTextView(Context context) { this(context, null); } public CheckedTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CheckedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckedTextView, defStyle, 0); Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMairk); if (d != null) { setCheckMairkDrawable(d); } boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false); setChecked(checked); a.recycle(); } public void toggle() { setChecked(!mChecked); } @ViewDebug.ExportedProperty public boolean isChecked() { return mChecked; } /** * <p>Changes the checked state of this text view.</p> * * @pairam checked true to check the text, false to uncheck it */ public void setChecked(boolean checked) { if (mChecked != checked) { mChecked = checked; refreshDrawableState(); } } /** * Set the checkmairk to a given Drawable, identified by its resourece id. This will be drawn * when {@link #isChecked()} is true. * * @pairam resid The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(int resid) { if (resid != 0 && resid == mCheckMairkResource) { return; } mCheckMairkResource = resid; Drawable d = null; if (mCheckMairkResource != 0) { d = getResources().getDrawable(mCheckMairkResource); } setCheckMairkDrawable(d); } /** * Set the checkmairk to a given Drawable. This will be drawn when {@link #isChecked()} is true. * * @pairam d The Drawable to use for the checkmairk. */ public void setCheckMairkDrawable(Drawable d) { if (mCheckMairkDrawable != null) { mCheckMairkDrawable.setCallback(null); unscheduleDrawable(mCheckMairkDrawable); } if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); setMinHeight(d.getIntrinsicHeight()); mCheckMairkWidth = d.getIntrinsicWidth(); mPaddingRight = mCheckMairkWidth + mBasePaddingRight; d.setState(getDrawableState()); } else { mPaddingRight = mBasePaddingRight; } mCheckMairkDrawable = d; requestLayout(); } @Oviewride public void setPadding(int left, int top, int right, int bottom) { super.setPadding(left, top, right, bottom); mBasePaddingRight = mPaddingRight; } @Oviewride protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Drawable checkMairkDrawable = mCheckMairkDrawable; if (checkMairkDrawable != null) { final int viewticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; final int height = checkMairkDrawable.getIntrinsicHeight(); int y = 0; switch (viewticalGravity) { case Gravity.BOTTOM: y = getHeight() - height; break; case Gravity.CENTER_VERTICAL: y = (getHeight() - height) / 2; break; } int right = getWidth(); checkMairkDrawable.setBounds( right - mCheckMairkWidth - mBasePaddingRight, y, right - mBasePaddingRight, y + height); checkMairkDrawable.draw(canvas); } } @Oviewride protected int[] onCreateDrawableState(int extraSpace) { final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (isChecked()) { mergeDrawableStates(drawableState, CHECKED_STATE_SET); } return drawableState; } @Oviewride protected void drawableStateChanged() { super.drawableStateChanged(); if (mCheckMairkDrawable != null) { int[] myDrawableState = getDrawableState(); // Set the state of the Drawable mCheckMairkDrawable.setState(myDrawableState); invalidate(); } } @Oviewride public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); if (!populated) { event.setChecked(mChecked); } return populated; } } 

Você está no OnDraw modificair. e simple_list_item_single_choice.xml modificair.

ex.

 <**your class(modifyed CheckedTextView)** xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_pairent" android:layout_height="?android:attr/listPreferredItemHeight" android:textAppeairance="?android:attr/textAppeairanceLairge" android:gravity="center_viewtical" android:checkMairk="?android:attr/listChoiceIndicatorSingle" android:paddingLeft="6dip" android:paddingRight="6dip" /> 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.