1

I have a simple listView with 4 textview as items and I want to change the background color of each item in the listView programatically. It is important for my case to not be limited by pre-compiled color values or states, and the solution must imply changing background color after the listView has been displayed.

Is this possible, how?

So far I've tried stuff like:

listView.getAdapter().getView(0, null, null)..setBackgroundColor(Color.GREEN);

or

listView.getAdapter().getView(0, listView.getAdapter().getView(i, null, null), null).setBackgroundColor(Color.GREEN);

also invalidated views after this lines, but it does not work.

Best Regards.

FeleMed
  • 601
  • 9
  • 28
  • possible duplicate of [Changing background color of ListView items on Android](http://stackoverflow.com/questions/2217753/changing-background-color-of-listview-items-on-android) – Alex K Sep 30 '14 at 15:44
  • @AlexK in my I would like this to be stateless and change the colors at runtime, by combination of colors (HEX), so this would not work for my case. Updates my question, thanks. – FeleMed Sep 30 '14 at 15:52
  • Ah, okay, my bad. So you searched and didn't find this answered before? – Alex K Sep 30 '14 at 16:12
  • @AlexK I've searched a lot and found mostly xml related answers, which for my case don't help much. I'll keep updating with the things I've tried but so far not haven't got any result. Thanks. – FeleMed Sep 30 '14 at 16:15

1 Answers1

0

overwrite getview in listadapter

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = super.getView(position, convertView, parent);



        TextView title = (TextView) v.findViewById(R.id.title);
        Color mColor = new Color();
        mColor.red(redvalue);
        mColor.green(greenvalue);
        mColor.blue(bluevalue);
        title.setTextColor(mColor);

OR

        mColor.parseColor("#rrggbb")
        title.setTextColor(mColor);

....
...


        return v;
    }

}
eurosecom
  • 2,932
  • 4
  • 24
  • 38