Android studio images - android

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

Related

Android Performance: load images for listView

I'm going to develop an application which shows a ListView which each row have a seperate image (like personal picture for contacts list). It seems I have two options:
1- Store all images in Asset Folder and load image using setImageDrawable() command.
2- Store all images in Drawable Folder and load theme using setImageResource(R.drawable.xxx)
So my questions is does they differ in performance? And how can I speed up listView rendering such that images displayed in acceptable speed.
There should not much performance different to access image from Drawable or asset folder. You can see the answer too - > Android: Accessing images from assets/drawable folders
But, When you using ListView you are recreating the view . So, Where ever you store the image all the images are will not feel much different .
There are not so much differences. Just for coding pattern changes.
assets/
Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource.
drawable/
Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
https://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes

Creating an image array with images from the assets folder?

[
Most of the searches I've done show solutions for creating an array with images in the drawable folder, I want to use the assets folder but I haven't been able to create an array successfully. I'm sure I'm just make a small mistake, but I'm completely stuck. Could anyone point me in the right direction?
Thanks in advance.
Not sure if this is what you're looking for, but an easy way to do it would be
List<Bitmap> mBitmapArray = new ArrayList<>();
mBitmapArray.add(gameScreen.getGame().getAssetManager().getBitmap(Asteroid1));
mBitmapArray.add(gameScreen.getGame().getAssetManager().getBitmap(Asteroid2));
mBitmapArray.add(gameScreen.getGame().getAssetManager().getBitmap(Asteroid3));
This would be creating a list as opposed to an array, but I figured that part was irrelevant. Obviously you could do the same idea with an Array.

How to add single Image to all drawables from mainActivity programatically Android

I want to add my image in Drawable s All files according to its size with single image
how it can perform .
Actually I retrieve images from DB Server..While no need to define Server logic in your Answer
You can't add resources in your app at runtime. So you will not be able to add image in your drawables folder.
However you can store in it in a file in your app directory using Context.openFileOutput.

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.
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

Android: how to show images in ImageSwitcher

I have an array of files contained in the sdcard: i would like to show an item in a ImageSwitcher but could not find the SetImageBitmap but only SetImageResource, but i have not these in res folder.
How can i do it?
use this below code instead of setImageBitmap. I think you have files in array.
imgSwitcher.setImageURI(Uri.fromFile(filename));

Categories

Resources