How to get image in res/drawable by name, not by id

All your problems with Audio, Video and Images.

How to get image in res/drawable by name, not by id

Postby phanthanhtrung86 » Thu Dec 24, 2009 5:35 pm

Hi all !
I have a database, and I have
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. create table Products (id integer, name text, picturename text, picture blob)
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
.
At the first time, I insert into table Product with 2 rows:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. insert into Prducts values(1,'Banana','banana.png',null)
  2.  
  3. insert into Prducts values(2,'Apple','apple.png',null)
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
After that, i want to update that table with the following condition that: I will look up the image's name which is the same with the picturename column in table Product.
I have tried the way that:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public int getPicID(String name)
  2.  
  3. {
  4.  
  5. if(name == "banana.png")
  6.  
  7. return R.drawable.banana;
  8.  
  9. if(name == "apple.png")
  10.  
  11. return R.drawable.apple;
  12.  
  13. return -1;
  14.  
  15. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Acording to getPicID , I will transfer it into byte[] to insert into table Products.
My question is: how can get image id by its name? does android support finding image by name in R.drawable?
Please help me!!!!!
phanthanhtrung86
Freshman
Freshman
 
Posts: 9
Joined: Tue Sep 15, 2009 9:39 am

Top

Postby qlimax » Thu Dec 24, 2009 6:35 pm

¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby phanthanhtrung86 » Fri Dec 25, 2009 8:15 am

Thanks you so much. It helps me solve this problem.
You are very kind.
phanthanhtrung86
Freshman
Freshman
 
Posts: 9
Joined: Tue Sep 15, 2009 9:39 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google Feedfetcher and 16 guests