0

I want to display all images reside in Assets folder: I have done some code as:

        mImageView = (ImageView) findViewById(R.id.grid_item_image);
        // to reach asset
        AssetManager assetManager = getAssets();
        // to get all item in dogs folder.
        String[] images = assetManager.list("FolderA");

        InputStream inputStream = getAssets().open("FolderA/" + images[0]);

        // load image as Drawable
        Drawable d = Drawable.createFromStream(inputStream, null);
        mImageView.setImageDrawable(d);
        inputStream.close();

This shows me 1 image from FolderA in Assets. now I want to show All images like Grid of Images.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Dipak Gami
  • 11
  • 3

2 Answers2

0
                mImageView = (ImageView) findViewById(R.id.grid_item_image);
                // to reach asset
                AssetManager assetManager = getAssets();
                // to get all item in dogs folder.
                String[] images = assetManager.list("FolderA");
                for(int i=0;i<images.length;i++
                {
                InputStream inputStream = getAssets().open("FolderA/" + images[i]);

                // load image as Drawable
                Drawable d = Drawable.createFromStream(inputStream, null);
               // this will display only last image
                mImageView.setImageDrawable(d);

                inputStream.close();
                }

get the list of drawable and create any list/recycler adapter and then u can display all the images

Shubham Jain
  • 2,365
  • 2
  • 17
  • 29
0
   public final String ASSETS_BASE_PATH = "file:///android_asset";

   // store image name in arraylist. 
   if (myArrayList.size() > 0) {
                GridAdapter myAdapter = new GridAdapter(MainActivity.this);
                myGridView.setAdapter(myAdapter);
    }

// And inside get use Glide to load images to image View.
// Add following dependency in app gradle.build file 
    compile 'com.github.bumptech.glide:glide:3.7.0' 


private class GridAdapter extends BaseAdapter {
        ViewHolder holder;
        private Context myContext;
        private LayoutInflater mInflater;

        public BannerAdapter(Context ctx) {
            this.myContext = ctx;
            this.mInflater = LayoutInflater.from(ctx);
        }

        @Override
        public int getCount() {
            return myArrayList.size();
        }

        @Override
        public Object getItem(int position) {
            return myArrayList.get(position);
        }

        public String getItemValue(int position) {
            return myArrayList.get(position).designName;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup viewGroup) {

            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.item_grid, null);
                holder = new ViewHolder();
                holder.myImageView= (ImageView) convertView.findViewById(R.id.imageView);
                convertView.setTag(holder);
                holder.positionViewHolder = position;
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            String url = myArrayList.get(position);

            String glideLoadUrl = url;

            glideLoadUrl = ASSETS_BASE_PATH + "/" + url;

            Glide.with(MainActivity.this).load(glideLoadUrl).into(holder.myImageView);
            return convertView;
        }
    }
jessica
  • 1,700
  • 1
  • 11
  • 17