Android中ListView的setBackgroundDrawable [英] setBackgroundDrawable for ListView in Android

查看:189
本文介绍了Android中ListView的setBackgroundDrawable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将可绘制对象设置为类中列表视图的背景?

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);
}

不当.

推荐答案

这是因为您没有给它一个Drawable,而是一个可绘制的ID.试试:

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

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

如果您正在参加活动.如果没有,那么您需要获取Context并在其上调用getResources().

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

这篇关于Android中ListView的setBackgroundDrawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆