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

Asked

Viewed 2,763 times

1

People would like to know if it is possible to upload an image from a drawable folder. For example, I have a Listview with several categories, when a category is selected I would like to see all the images related to this category, and so the user can access them. But I don’t know how to do that. I thought to add all images in folders in the drawable and so insert into the database and select to display these categories.inserir a descrição da imagem aqui

1 answer

0


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

But it is best practice to actually save the link to the image in the database (better yet: save the link to an external database), and not the image in the drawable folder... Then you upload the link and the user will download the image. I advise the use of the library Glide to do this automatically.

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

You can still make an int array and hold all the images in the drawable folder (because R.drawable.img is int) and save in the database only the position of that array... at position 10 is the image of a giraffe...so every time the program opens, the array is loaded and at position 10 the returned database will be the image of the giraffe... Stays: Glide.with(this).load(arrayDeImagens[10]).into(imageview)

  • Thank you! I will search about the Glide library.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.