Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setBackgroundDrawable for ListView in Android

How do I set a drawable as the background for a list view in a class?

if (array1.size() < 8)
{
    lv1.setBackgroundDrawable(R.drawable.bgimghs2b);
}

is improper.

like image 938
erdomester Avatar asked Jun 04 '11 15:06

erdomester


1 Answers

That's because you're not giving it a Drawable, but an ID of a drawable. Try:

lv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.bgimghs2b))

If you're in an activity. If not, then you need to get a Context and call getResources() on that.

like image 95
dmon Avatar answered Oct 07 '22 13:10

dmon