Search code examples
androidlistviewandroid-arrayadaptergetview

How to obtain the text color of a single item within an Android ListView


My ListView contains items that are different text colors. I need to grab the color state of each item to to be saved within the onSaveInstanceState of my fragment.

    ListView lvItems = (ListView) getActivity().findViewById(R.id.lvItems);
    lvItemsArray.add("Testing1234");

    lvItemsAdapter = new ListViewAdapter(getActivity(), lvItemsArray);
    lvItems.setAdapter(lvItemsAdapter);

Solution

  • Found it from another user on here, thanks.

        View view = ListAdapter.getView(0, null, null);
        TextView textView = (TextView) view.findViewById(R.id.myitemRow);
        ColorStateList mlist = textView.getTextColors();
        int color = mlist.getDefaultColor();