I'm trying to have a checkbox that is red when the app starts up. It is a custom circle checkbox, and they're in xml files. If the user clicks it, then it will turn to yellow. If the user clicks it again, then it will turn green. I'm trying to have the checkbox when clicked to not necessarily be unchecked, but to have it checked every time a user clicks on it. I don't know if this is possible or not. I have been researching how to check a checkbox multiple times and haven't found anything.
Here is how I'm trying to check if is checked more than once.
chkInProgess.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int count = 0;
if (chkInProgess.isChecked()){
count++;
}
if (count == 1) {
chkInProgess.setButtonDrawable(R.drawable.custom_yellow_checkbox);
}
if (count == 2){
chkInProgess.setButtonDrawable(R.drawable.custom_green_checkbox);
}
}
});
Here is my checkbox code.
<CheckBox
android:id="@+id/chkInProgess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/inProgress"
android:layout_below="@id/txtGather"
android:button="@drawable/custom_red_checkbox"
android:checked="true"
android:textSize="11dp"
android:layout_marginLeft="25dp"
/>
Here is my circle xml code. The yellow and green checkbox xml code is similar just different hex values.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">
<item android:state_checked="true">
<layer-list>
<item>
<shape android:shape="oval">
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#FFF" />
<solid android:color="#dc7174"/>
<size
android:width="23dp"
android:height="23dp" />
</shape>
</item>
<item
android:width="8dp"
android:height="2dp"
android:top="14dp"
android:left="4dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#fff"/>
</shape>
</rotate>
</item>
<item
android:width="13dp"
android:height="2dp"
android:top="12dp"
android:left="7dp">
<rotate
android:fromDegrees="-45">
<shape android:shape="rectangle">
<solid android:color="#fff"/>
</shape>
</rotate>
</item>
</layer-list>
</item>
</selector>
Any help will be much appreciated. Thanks!
Aucun commentaire:
Enregistrer un commentaire