How to get images dynamically from drawable folder?

by Mansoor Malik   Last Updated December 06, 2018 11:11 AM

I'm getting images manually like private int[]image = {R.drawable.image1,R.drawable.image2,R.drawable.image3}; If I have some 50 images I cant give each and every file name in array so it needs to be dynamic how can I achieve this. And also please tell me where to put my dynamically code

public class SwipeAdapter extends PagerAdapter {
private int[]image =  {R.drawable.image1,R.drawable.image2,R.drawable.image3};private Context cx;

SwipeAdapter(Context cx){;

public int getCount() {
    return image.length;
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
    return (view==(RelativeLayout)object);

public Object instantiateItem(@NonNull ViewGroup container, int position) {

    LayoutInflater layoutInflater = (LayoutInflater) cx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    assert layoutInflater != null;
    View view= layoutInflater.inflate(R.layout.page_fragment,container,false);
    ImageView imageView= view.findViewById(;
    return view;

public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
    container.removeView((RelativeLayout) object);


Related Questions

.dd , .raw and .e01 file format in android

Updated July 10, 2015 15:04 PM

How to crop an image?

Updated May 10, 2016 08:04 AM