Search code examples
androidimageimageviewandroid-resources

How To store image view id's in array and set image resource on specific image view element


imgv is a array contain id's of image view

How do I store ImageView IDs in an array and set Image resource on a specific ImageView element?


Solution

  • You can't use setImageResource on int array this method must be used on ImageView object

    Sets a drawable as the content of this ImageView.

    More explanation in documentation ImageView

    Simply you can do something like this

        int[] array = {R.drawable.imag_view_1,R.drawable.imag_view_3,R.drawable.imag_view_2};
    
        imageView.setImageResource(array[0]);