RaagaSudha
RaagaSudha

Reputation: 397

How to get the image from drawable folder in android?

I am working on quiz application. I stored the column data in the following form in sqlite database. enter image description here

I am able to retrieve the question but now I need to retrieve the image of that particular question. I kept the images in drawable folder. But I need to change the i.e src="/test/image1.png" to src="/drawable/image1.png". If I change the path like the path of the image in sqlite colum at then can I get the image which I kept in my drawable folder? Please help me regarding this...

Thanks in advance

Upvotes: 2

Views: 18540

Answers (4)

Harsh Dev Chandel
Harsh Dev Chandel

Reputation: 763

just name the src="image1.png" and put the files in your assets folder images and html

Upvotes: 0

NiVeR
NiVeR

Reputation: 9806

It can be done like this aswell:

 Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);

where this refers to the context of the actual activity.

Upvotes: 6

pushkar kandpal
pushkar kandpal

Reputation: 71

getResources().getIdentifier(name,"drawable", getPackageName());

Upvotes: 2

Lalit Poptani
Lalit Poptani

Reputation: 67296

I would insist that in database you can just give the name of the image and then you can get the image using getIdentifier,

getResources().getIdentifier(name,"drawable", getPackageName());

Where name will be the name of your image i.e - "image1"

Upvotes: 7

Related Questions