i have a listview which has an adapter, which worked properly, but then i added some code because i wanted the rows to be different colors, after that, the onclick color doesnt show up.
Here is the code i added:
if (position % 2 == 0)
vi.findViewById(R.id.parentL).setBackgroundColor(ctx.getResources().getColor(R.color.row1));
else
vi.findViewById(R.id.parentL).setBackgroundColor(ctx.getResources().getColor(R.color.row2));
TL:DR
Instructions
First, you need to set your ListView to to be transparent
Inside your Adapter’s
onCreate()method, set:Next, inside
Adapter‘sgetView()include the following codewhere selector.xml is
and selector2.xml is
don’t forget to include a colors.xml
Sample Project
here are the files for a sample project I configured for you. You probably want to do a Project > Clean before anything else.
Some files can be ignored in this app, since I modified an existing sample that did something very different.
Screenshot
here is what my example app looked like