Listview with alternating resources in Android
- by Fran
Hi!
I have a ListView and an adapter that sets alternating background colors to the list items overwriting getView Method in my adapter.
I want to go further and I would to set to each row a Resource background. I try in getView call the method setBackgroundResource:
private int[] messages = new int[] {R.layout.message,R.layout.message2};
//...
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
int MessagePos = position % messages.length;
v.setBackgroundResource(messages[MessagePos]);
return v;}
But this not work, and I the message throws by exception is File res/layout/message.xml from drawable resource ID #0x7f030004
Any ideas?
Thanks!