How to read all image from sub folder of assets in android
Create new project and add an imageswitcher to activity_main.xml then open MainActivity.java firstly we need to reach assets folder in android to reach assets folder there is an assets manager basicly you can use assets manager like that
AssetManager assetManager = getAssets(); /* this will read main folder of assets if you need read sub folder just add folder name before file (subfolder/filename) */ InputStream inputStream= assetManager.open("File name");
We want to read all file from sub folder of assets so we need a list so we will create list. Firstly, I will create a list of file as a string array and calculate count of file in folder to create a loop then,I will create a drawable array to keep all image in it.
try { // to reach asset AssetManager assetManager = getAssets(); // to get all item in dogs folder. String[] images = assetManager.list("dogs"); // to keep all image Drawable[] drawables = new Drawable[images.length]; // the loop read all image in dogs folder and aa for (int i = 0; i < images.length; i++) { inputStream = getAssets().open("dogs/" + images[i]); Drawable drawable = Drawable.createFromStream(inputStream, null); drawables[i] = drawable; } } catch (IOException e) { // you can print error or log. }
I have read all image and add all of them an imageswitcher and to swipe I add two image button then the project was finished I will give you source code of this project below.
End of Project
4 comments
Great job
Thanks for sharing it ❤️
selman bey mssql ile veritabanındaki resimleri nasıl çekebiliriz bir listview da
Merhabalar Turgut bey,
Android üzerinde uzun süredir bir çalışma yapmadığımdan size yardımcı olamıyorum maalesef fakat aşağıda verdim linke bir göz atmanızda fayda var. Reading Images From MSSQL
Thank you so much for this post