Android 如何在单击listview中的特定项时将listview的checkeditem框的颜色设置为除绿色以外的其他颜色?

Android 如何在单击listview中的特定项时将listview的checkeditem框的颜色设置为除绿色以外的其他颜色?,android,listview,Android,Listview,我有一个列表视图。当用户选择一个特定项目时,复选框的颜色变为绿色…我希望复选框的颜色变为橙色或红色..这怎么可能? <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="new checkbox" android:background="@drawable/checkbox_background" android:button="@draw

我有一个列表视图。当用户选择一个特定项目时,复选框的颜色变为绿色…我希望复选框的颜色变为橙色或红色..这怎么可能?


<CheckBox android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="new checkbox"
 android:background="@drawable/checkbox_background" 
 android:button="@drawable/checkbox" />
@drawable/复选框如下所示:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_checked="true" android:state_focused="true"
  android:drawable="@drawable/checkbox_on_background_focus_red" />
 <item android:state_checked="false" android:state_focused="true"
  android:drawable="@drawable/checkbox_off_background_focus_orange" />
 <item android:state_checked="false"
  android:drawable="@drawable/checkbox_off_background" />
 <item android:state_checked="true"
  android:drawable="@drawable/checkbox_on_background" />
</selector>

“背景上的复选框”“焦点上的复选框”“红色”、“背景下的复选框”“焦点上的复选框”“橙色”、“背景下的复选框”和“背景上的复选框”是您所需的drawble文件夹中的复选框图像


1- implement the OncheckedLinstener and notify data set changed to list 
2- put check in getview if(chk.isChecked()){//setBG color green }else {red} 
2- either set the selector to checkbox or change the BG color of chk box in if else in getview
@drawable/复选框如下所示:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_checked="true" android:state_focused="true"
  android:drawable="@drawable/checkbox_on_background_focus_red" />
 <item android:state_checked="false" android:state_focused="true"
  android:drawable="@drawable/checkbox_off_background_focus_orange" />
 <item android:state_checked="false"
  android:drawable="@drawable/checkbox_off_background" />
 <item android:state_checked="true"
  android:drawable="@drawable/checkbox_on_background" />
</selector>

“背景上的复选框”“焦点上的复选框”“红色”、“背景下的复选框”“焦点上的复选框”“橙色”、“背景下的复选框”和“背景上的复选框”是drawble文件夹中所需的复选框图像

1- implement the OncheckedLinstener and notify data set changed to list 
2- put check in getview if(chk.isChecked()){//setBG color green }else {red} 
2- either set the selector to checkbox or change the BG color of chk box in if else in getview
如果你想优化的话

使用tag和OnCheckdInstener中的复选框设置列表项的位置。您将获得视图。只需使用getFirstVisiblePosition和getLastVisiblePosition、getChildAt(int index)从选项卡的视图中获取位置,然后对其进行更改

如果你想优化的话


用tag和OncheckedLinstener中的复选框设置列表项的位置。您将获得视图。只需从选项卡的视图中获取位置,并使用getFirstVisiblePosition和getLastVisiblePosition、getChildAt(int index)进行更改。

可能重复的也请在下一个问题上选择较短的标题。两行太多了,问题正文用于进一步描述。可能的重复也请在下一个问题上选择一个较短的标题。两行太多了,问题的主体是用来作进一步的描述的。你能告诉我如何设置绿色或红色吗?我不知道怎么做?你能告诉我如何改变chk盒的BG颜色吗?你在使用自定义适配器吗?然后简单地改变你在getview中膨胀的线性布局的颜色……不,我没有使用自定义适配器。实际上我的listview是在运行时生成的,你在使用哪个适配器?你能告诉我如何设置绿色或红色吗……我不知道怎么做?你能告诉我如何更改chk盒的BG颜色吗?你在使用自定义适配器吗?然后简单地更改你在getview中膨胀的线性布局的颜色……不,我没有使用自定义适配器。实际上我的listview是在运行时生成的。你在使用哪个适配器?