[TinyTut] - Get Resources by Name ( getIdentifier(...); )

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Re: [TinyTut] - Get Resources by Name ( getIdentifier(...);

Postby Dliswa » Mon Jun 13, 2011 1:12 pm

I have some image names stored in a database (Fully Qualified Like R.drawable.SomeImageName) Column type is Integer, but the images themselves are in the /res/drawable folder of the application.

I need to assign these images to some views at runtime, and I'm currently doing it this way:


and someView.setBackgroundResource(getResources().getIdentifier(cursor.getString(Image_Column_Index, null, null));

Both of these method doesnt work

thanks in advance.
Posts: 30
Joined: Fri Oct 15, 2010 5:56 am


Re: [TinyTut] - Get Resources by Name ( getIdentifier(...);

Postby sliTh » Tue Jul 05, 2011 9:03 pm

uibi wrote:No idea what files you typed this code in to. You lost me on first row of code... is it the main.xml or what?
Being completely new to programming i find it very hard to follow most guides (in my book as well) since the name of the file edited is left out. I might be a complete R-tard but being new to the Eclipse environment I'm overwhelmed as it is.

I would highly recommend learning programming before you start Android. Specifically Java and XML.
The code he is showing is Java in your Activity, probably "MainActivity" or something of that sort, under the src folder.
Posts: 3
Joined: Thu Mar 31, 2011 6:15 am

Re: [TinyTut] - Get Resources by Name ( getIdentifier(...);

Postby ginlemon » Mon Sep 26, 2011 6:21 pm

I've got a problem...when i call getResources() the app crashes :-S
Anyone know why this happens??

Thank You
Posts: 4
Joined: Mon May 23, 2011 11:18 am

Re: [TinyTut] - Get Resources by Name ( getIdentifier(...);

Postby srikkanth007 » Thu Dec 15, 2011 7:53 pm

Hi plusminus,
I have a unique problem here hoping i get some inputs from you and all who can help.We are trying to integrate our client app with 2 other vendor module apps.The problem here there App has already been built and it has close to 3000 resources.So what we are trying to do is include their Activity as Jar file(They Wont be sharing their code) and get their resources. This getResources.getidentifier works well but just wanted to know is there any way we can point the vendor modules to point the resources in the Client app as you know .class simply refers to the ID from the vendor app.

1 more thing I assume getResources.getidentifier is a pretty heavy call.So will it work for app which has more than lets say 100 screens or 3000 resources???

Waiting for your replies....
Once Poster
Once Poster
Posts: 1
Joined: Thu Dec 15, 2011 7:45 pm


Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests