I am a beginner at Android.
I want to select multiple images from gallery and view them to a horizontal scroll view. Currently I\'m able to select a single image and
Start activity to choose your image with this intent
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), UploadingHelper.REQUEST_CODE);
then select any number of images you want and then in your activity result
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && intent.getClipData() != null) {
int numberOfImages = intent.getClipData().getItemCount();
for (int i = 0; i < numberOfImages; i++) {
try {
ImageData imageData = new ImageData();
imageData.uri = intent.getClipData().getItemAt(i).getUri();
Bitmap bitmap = getBitmap(intent.getClipData().getItemAt(i).getUri());
imageData.icon = Bitmap.createScaledBitmap(bitmap, getPixelsFromDP(widthOfImages), getPixelsFromDP(widthOfImages), false);
images.add(imageData);
} catch (Exception e) {
Logger.log(e);
}
}
}
This is the Image Data class used.
public class ImageData {
public Bitmap icon;
public Uri uri;
}
Sorry I forgot add the method
private int getPixelsFromDP(float dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, Resources.getSystem().getDisplayMetrics());
}