i selected 10 images from gallery but how to show the selected images

260 views
0
ganeshvelsol | 12 xp

on button click i opened gallery and  selected 10 images , but i want to show selected images in separate layout .

Thanks in advance.

0
Sindhuja K | 201 xp
Best Answer ganeshvelsol selected as best answer
  1. Add a checkbox at the top of every image in gallery.

<ImageView
        android:id=“@+id/galleryImageView”
        android:layout_width=“140dp”
        android:layout_height=“170dp”
        android:src=“@mipmap/ic_launcher”
        android:scaleType=“centerCrop”/>

    <CheckBox
        android:id=“@+id/selectCheckBox”
        android:layout_width=“wrap_content”
        android:layout_height=“wrap_content”
        android:layout_alignTop=“@+id/galleryImageView”
        android:layout_alignParentRight=“true”
        android:layout_centerVertical=“true”/>

2. Select the images required and get the positions of checked items.
//Show hide select button if images are selected or deselected
    public void showSelectButton() {
        ArrayList<String> selectedItems = imagesAdapter.getCheckedItems();
        if (selectedItems.size() > 0) {
            selectImages.setText(selectedItems.size() + ” – Images Selected”);
            selectImages.setVisibility(View.VISIBLE);
        } else
            selectImages.setVisibility(View.GONE);
    }
3. Fill the checked items into an array list.

ArrayList<String> selectedItems = imagesAdapter.getCheckedItems();

4. Send the result to an activity with selected images.

Intent intent = new Intent();
intent.putExtra(MainActivity.CustomGalleryIntentKey, selectedItems.toString());//Convert Array into string to pass data
setResult(RESULT_OK, intent);
finish();
break;