如何检查本地Drawable,缺少一个如何从远程资源创建一个?

csc*_*yer 1 sqlite android drawable http-streaming

我需要从云数据库中获取一个给定的可绘制名称,并检查本地包中是否存在匹配的Drawable.如果没有,我需要创建一个图像的本地副本供我使用,所以我不会经常访问远程资源.最好的方法是什么?我可以访问数据库,执行SQL,所有这些.我只需要知道如何A)检查本地包是否存在一个名为(例如)'icon'的Drawable,如果它本地不存在,我需要知道如何创建和存储本地副本(通过HTTPstream可能吗?).

Raf*_*l T 6

1:像这样检查你的抽签:

int resID = getResources().getIdentifier("icon", "drawable", "your.package.namespace");
if (resId == 0){
    //drawable isn't there. You have to fetch it through Http or whatever
} else {
    //getDrawable like this
    Drawable d = getResources.getDrawable(resId);
}
Run Code Online (Sandbox Code Playgroud)

2:你不能把一个下载的drawable放在drawableFolder中.但是你可以将它下载到res/raw或sdcard.如果您已下载此特定drawable,请注意检查该位置.