简体   繁体   中英

display image from array in android

I declared the following array which contains images:

private int[] LEAVES = { 
            R.drawable.leaf_green, 
            R.drawable.leaf_red,
            R.drawable.leaf_yellow,
            R.drawable.leaf_other,
        };

If I would want to show one image from the array how can I refer to a specific image? let's say I would want to refer to LEAVES[1]. How can I display it?

Actually setImageResource method sets a drawable as the content of ImageView. It takes id of drawable as argument. Here we have array of drawable ids. we can pick drawable id from array to use. below code shows syntax of of the method.

imageView.setImageResource(LEAVES[1]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM