I am working on quiz application. I stored the column data in the following form in sqlite database.
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
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"
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.
getResources().getIdentifier(name,"drawable", getPackageName());
just name the src="image1.png"
and put the files in your assets folder images and html
Related
I am trying to add an image slide on my android app.
When I try to add the source for the image, from drawable folder, I can't select the iamges.
Here, a little screenshot to understand better the problem:
Screen
What can I do to solve it?
Thank you for your answer.
the naming convention shouldn't be a number. declare it in small letters, like this -> image_one ......e.tc.
You should use PNG or WEBP images as your drawables.
As you may already know variable names should not start with a number. So in your case using a number as your image name forces the compiler to generate a variable named as your drawable name which cannot be accepted in programming, hence the constant R.drawable.1 does not get generated. Try renaming your drawable to an alphabetical equivalent.
I want to store images for my quizz app on android with ArrayList.The images must be stored in the folder drawable.
Is someone can explain me how to do this?
Thank you
Pate your Images in the drawable folder and access them from your activity using R.drawable.imagenames.
Paste the images in your drawable folder.
Create a ArrayList in your code and add all the images to the arraylist
ArrayList<View> imageList = new ArrayList<>();
imageList.add(image1);
imageList.add(image2);
...and so on
In my app, there may be more than thousand of small image/ icon
and they will be display in views inside the list view or grid view
While I am wondering how the data should be store
1. covert to the string array and store in the database.
2. in the drawable folder (and how should the path store in the database?)
3. other better method?
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon.
You should store the images in Drawable folder. The Drawable folder is pre-compiled. Which means that the images will be fetched much faster than from Database.
I'm new to development and I'm stuck at a point where I don't know what would be the best possible solution.
I have a list of 26 images saved in the drawable folder. Lets say a to z. When user clicks on the right side layout they should navigate forward and if the user clicks on the left side layout they should navigate backwards.
My issue is that these are images and their IDs as retrieved by android are random int values. I can't use that to compare which letter of alphabet should be displayed next.
How do I go about this problem?
If I name the images a.png, b.png, c.png... How do I retrieve the name later from the ID?
Will I be able to store the drawables as a key value pair using collection framework?
You can get the name of your resource by
String resourceName = getResources().getResourceName(resId);
You can store all the image ids in an array.
For example,
int images[]=new int[]{R.id.a,R.id.b,...,R.id.z};
Then you need to maintain the position in array of the current image every time you navigate.
For example change position as
pos=(pos+1)%26;
for next image and
pos=(pos-1)%26;
for previous image
and then use
setImageResource(images[pos]);
if its an ImageView or ImageButton, or using getResources().
You can retrive the ids of images in drawable folder like this...
int imagekey=getResources().getIdentifier(url.toLowerCase(),"drawable",getPackageName());
where url is the name of the images in the drawable folder
Is it possible to get the path of an image in string form in android like
res/drawable/image.png
Or is their any other way for getting string path of an image that is placed in drawable.
No, it is not.
Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
e.g. will give you the default launcher icon. It is not possible to get the exact path for an image , that is stored in drawable.
Why not? When you compile your app to an *.apk file, all resources (ok, except from them in /raw) are compiled as well. You can only acces them, using their R. id.
Solution? Not really, you could copy them to a location on the sd card for example. Now you know the location :)
its not possible to get path of drawable image directly , but you can get this by storing it in internal memory or sdcard of device.For this i have written blog.. check out the link
here
i am sure it will help you.