How to insert images in Android Studio from a drawable folder?

1

People would like to know if it's possible to load an image from a drawable folder. For example, I have a ListView with several categories, when a category is selected I would like all the images related to this category to appear, so that the user can access them. But I do not know how to do that. I thought about adding all the images into folders in the drawable and thus inserting them in the bank and making a select to present these categories

    
asked by anonymous 27.09.2016 / 21:41

1 answer

0
ImageView imageview = (ImageView) findById(R.id.imagemXml);
imageview.setImageResource(R.drawable.imagem1);

But it is better practice to actually save the link to the image in the database (better still: save the link to an external database), not the image in the drawable folder ... Then you load the link and the user will download the image. I recommend using the Glide library to do this automatically.

It stays: Glide.with(this).load("www.imagem.com.br/img1").into(imageview) No load can also put drawable images. It is: Glide.with(this).load(R.drawable.imagem1).into(imageview)

You can also make an array of int and hold all the images in the drawable folder (because R.drawable.img is int) and save to the bank only the position of that array ... in Position 10 is the image of a giraffe ... then, every time the program opens, the array is loaded and in position 10 the bank returned will be the image of the giraffe ... there it is simply taken as arrayDeImagens [10]. .. It works: Glide.with(this).load(arrayDeImagens[10]).into(imageview)

    
27.09.2016 / 21:52