Search code examples
androidarraylisttextcolor

add list item with custom text color


i want my code to add a list item with a the text color GREEN if a certain condition is met, otherwise i just want it to add the item with no specified text color

heres my code:

                if (cursor.getString(4).equals("yes")) {
                    achievementList.add(cursor.getString(1)+" (completed)");
                }
                else {
                    achievementList.add(cursor.getString(1));
                }

ive tried using setTextColor(Color.GREEN) on the cursor.getString as well as the achievementList.add, and both are throwing errors. whats the proper way of doing this?


Solution

  • Basically you should create your own ArrayAdapter and extend from the default one. Than you should override getView() and create, fill and modify the views there. There you can set the text color of the TextView of your choise.

    There are a lot of good tutorials out there, just search for it.