Android的setbackgrounddrawable列表视图 [英] Android setbackgrounddrawable listview

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

问题描述

如何设置一个可绘制为背景的类列表视图?

How to set a drawable as background for a listview in a class?

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

是不正确的。

is improper.

感谢。

推荐答案

那是因为你没有给它一个绘制对象,但绘制的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))

如果你在一个活动。如果没有,那么你需要获得一个上下文和呼叫 getResources()这一点。

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

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

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