Image array in android

前端 未结 3 1865
眼角桃花
眼角桃花 2021-02-04 10:59

I am trying to use an array of images then set my ImageView to one of the images in the array. My first instinct was to use an array of strings with the image names but this did

3条回答
  •  鱼传尺愫
    2021-02-04 11:41

    You can use the resources from drawable-mdpi and store them in an array of integers like

    private static final Integer[] Icons = {
        R.drawable.bg_android_icon,
        R.drawable.bg_sunrise_icon,
        R.drawable.bg_sunset_icon,
        ......
    };
    

    And then you can use it in a loop with Postion ranging from 0 to Icons.length and set it to ImageView

    ImageView.setBackground=getResources().getDrawable(Icons[Position]);
    

提交回复
热议问题