Reputation: 39
How to retrive all images from folder named 'imagesf' in assets folder and using it as int[] instead of
int[] mImages = new int[]{
R.drawable.pic1
,R.drawable.pic2
,R.drawable.pic3
,R.drawable.pic4
};
To use it in a viewpager
Upvotes: 1
Views: 1701
Reputation: 1764
Use below code to get all image name from 'imagesf' in assets folder
private List<String> getImage(Context context) throws IOException {
AssetManager assetManager = context.getAssets();
String[] files = assetManager.list("imagesf");
List<String> it = Arrays.asList(files);
return it;
}
and get one by one image as Bitmap by using below code iterating in loop:
private Bitmap getBitmapFromAsset(String strName)
{
AssetManager assetManager = getAssets();
InputStream istr = null;
try {
istr = assetManager.open(strName);
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}
Upvotes: 3