Listview with alternating resources in Android

Posted by Fran on Stack Overflow See other posts from Stack Overflow or by Fran
Published on 2010-05-10T09:30:22Z Indexed on 2010/05/10 9:34 UTC
Read the original article Hit count: 335

Filed under:
|
|
|
|

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!

© Stack Overflow or respective owner

Related posts about android

Related posts about listview