0

So I have a list of checkboxes in a list array populated with various text and a custom checkmark that effectively shows when I click the specific item. However, I can't seem to change the text color of the text in the item that is checked. I want to change it to the same color as the checkmark. When I do click on the item and when the text color is set to the textColor code below, the text turns pink! which is not the color I want. It seems to be a default color. My question is then how do I change the textColor of the particular checkbox that I have checked that is embedded in a listview? I have searched on this website and others but I couldn't find an answer that could help me.

text color

<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:textColor="@color/purple_color" /> </selector> 

and purple checkmark:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@android:color/transparent" android:state_checked="false"/> <item android:drawable="@drawable/ic_check_black_24dp" android:state_checked="true"/> </selector> 

and list view in the activity:

<ListView android:id="@+id/myList" android:paddingTop="12dp" android:layout_marginLeft="44dp" android:layout_marginRight="44dp" android:layout_width="fill_parent" android:layout_height="wrap_content" /> 

and the individual list item:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <CheckBox android:id="@+id/orientation_type" android:layout_width="fill_parent" android:layout_height="44dp" android:gravity="left|center_vertical" android:textColor="@drawable/check_box_text_color_purple" android:textSize="17dp" android:layoutDirection="rtl" android:button="@drawable/check_purple" /> </LinearLayout> 

and the array adapter:

public class orientation_adapter extends ArrayAdapter<orientation_item> { private Context mContext; int mResource; public orientation_adapter(@NonNull Context context, int resource, @NonNull ArrayList<orientation_item> objects) { super(context, resource, objects); this.mContext = context; this.mResource = resource; } @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { String orientation = getItem(position).getOrientation(); gender_item user_orientation = new gender_item(orientation); LayoutInflater inflator = LayoutInflater.from(mContext); convertView = inflator.inflate(mResource, parent, false); //TextView orientation_type = (TextView) convertView.findViewById(R.id.orientation_type); CheckBox orientation_type = (CheckBox) convertView.findViewById(R.id.orientation_type); orientation_type.setText(orientation); return convertView; } } 

and the main activity:

ArrayList<orientation_item> list = new ArrayList<>(); //items created and added here adapter = new orientation_adapter(ChooseOrientation.this, R.layout.orientation_unit, list); myList.setAdapter(adapter); 
2
  • stackoverflow.com/questions/27713829/… will this help you.. Commented Apr 14, 2020 at 8:20
  • I ended up solving the problem. Not really sure what was wrong though. That's a good post though that could be beneficial. Commented Apr 14, 2020 at 16:16

1 Answer 1

0

I ended up applying this to the android:textColor field in the individual component xml of the listview. This solved the problem but is similar to what I did before. Android seems to respond better when you use actual color codes instead of linking to colors.

<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false" android:color="#000000"/> <item android:state_checked="true" android:color="#FF6C63FF"/> <!-- checked --> <item android:color="#ffffff"/> <!-- anything else --> </selector> 
Sign up to request clarification or add additional context in comments.

Comments