Something like:
private Bitmap getFromName(String bitmapName)
{
Bitmap target = null;
try
{
int value = getFieldValue(bitmapName, R.drawable.class);
InputStream is = context.getResources().openRawResource(value);
target = BitmapFactory.decodeStream(is);
}
catch (Throwable e)
{
// couldn't find it
}
return target;
}
public int getFieldValue(String name, Class obj) throws
NoSuchFieldException, IllegalArgumentException,
IllegalAccessException
{
Field field = obj.getDeclaredField(name);
int value = field.getInt(obj);
return value;
}
On Feb 14, 4:34 pm, stanchat <[email protected]> wrote:
> I have a SQLite database and one of the tables has a column that is
> the string name of a jpeg file..
>
> For instance the column is called "PhotoID" and a record value is say
> "photoone.jpg"
> I have strored all the actual jpegs in the drawable resouce directory.
>
> I would like to be able to programmatically access the resources with
> having to prep or setup the link. I have about 100 photos but do want
> to setup a link to the actual resource id.
>
> For instance the R class has the following setting
> ======================================
>
> public static final int david_beckham=0x7f020011;
>
> I have created a record in my DB as follows;
>
> "INSERT INTO Celebrity_Trump_Raw_Data (Rank, CelebrityName, PayMil,
> WebRank, PressRank, TVRank, PhotoId) VALUES ('5', ' David Beckham',
> 50, '10', '3', '18', 'David_Beckham.jpg');",
>
> I would like to do something like this:
>
> int curr_pic_res = R.drawable.(String.tolower(Celeb.PhotoID));
>
> Is this possible or do I have to create the resource links manaully.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---