0

I've created a custom video gallery which populates all your video from the phone and shows it to you. I've succeeded in making the gallery, and yes it shows the thumbnails of the videos not the video. Now the next thing is that to select those videos either or multiple.

I've followed this link but couldn't find the appropriate answer my code is here :

to select multiple images from the gridview

I've set the choice mode of my grid view to ListView.CHOICE_MODE_MULTIPLE but couldn't find whether it is working or not. I need some border in order to find out whether I've implemented the correct code or not whether it has a deselection mode or not if the user want to deselect the video thumbnail.

Second thing I need to populate my selections in another activity in a listview which is horizontally scrollable.

This is my code so far. Everything is working except the two problems which I have just mentioned. I do not want to make checkboxes just the border thing but struggling to find my solution. I know here I can best people with best results.

public class AddFragment extends Fragment {

private ImageButton imageButton;
private GridView gridView;

ArrayList<File> list = new ArrayList<>();

public AddFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_add, container, false);
    imageButton = (ImageButton) view.findViewById(R.id.gotoButton);
    gridView = (GridView) view.findViewById(R.id.grid_view);
    videoReader(Environment.getExternalStorageDirectory());
    gridView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    gridView.setAdapter(new ImageAdapter(getContext()));



    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            //for making the button visible as ssonas the item gets selected
            imageButton.setVisibility(view.VISIBLE);

        }
    });

    return view;
}

void videoReader(File root) {


    File[] file = root.listFiles();

        for (File aFile : file) {
            if (!aFile.isDirectory()) {
                if (aFile.getName().endsWith(".mp4")) {
                    Log.e("VIDEO_FILE=====", aFile.getName());
                    list.add(aFile);
                }
            } else {
                videoReader(aFile);
            }
        }
}


public class ImageAdapter extends BaseAdapter {

    private Bitmap bitmap;

    private final Context context;

    private ImageAdapter(Context c) {
        context = c;
    }

    //for the video numbers
    @Override
    public int getCount() {
        return list.size();
    }

    //for getting the video items position vise
    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

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

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

        ImageView picturesView;
        if (convertView == null) {
            picturesView = new ImageView(context);
            if (list.get(position).toString().contains(".jpg")) {
                bitmap = BitmapFactory.decodeFile(list.get(position).toString()); //Creation of Thumbnail of image
            } else {
                if (list.get(position).toString().contains(".mp4")) {
                    bitmap = ThumbnailUtils.createVideoThumbnail(list.get(position).toString(), 1); //Creation of Thumbnail of video
                }
            }
            picturesView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            //picturesView.setPadding(8, 8, 8, 8);
            picturesView.setLayoutParams(new GridView.LayoutParams(200,200));
            picturesView.setImageBitmap(bitmap);
        } else {
            picturesView = (ImageView) convertView;
        }

        return picturesView;
    }

} }

I've followed one more link but it is picking the photos from the gallery itself. I need to pick those thumbnails of the videos and get the videos in the next activity as a thumbnails but when we select the videos will be there in the VideoView.

Android selecting multiple images from the gallery and then populating in the gridview

**EDITS : **

OUTPUTS ON WHICH I'M WORKING

1. Here the thumbnails of the video comes up and you can see the checked video which is of red colored border, the page is multiple selectable and you can deselect it too.

The image of the first page

2. Now here comes the activity which contains the selected video you chose from the previous video thumbnails. P.S. You are going from a fragment to activity which is Edit Section so we need to take the selected ones to the activity. In below you can see that the video's thumbnail is there at the bottom which is selected in the previous page.

The edit activity

Alok
  • 8,452
  • 13
  • 55
  • 93
  • any ideas! please help to get this working! – Alok Jul 21 '17 at 09:39
  • You can use any other view instead of checkbox for selecting the video thumbnails and can use the same code of checkbox. – Surender Kumar Jul 21 '17 at 10:15
  • @SurenderKumar could you please give me some demonstration as to what to do. Just a hint code in mine code. Please that'd be grateful. – Alok Jul 21 '17 at 10:17
  • to add in my .xml layout I have not specified any checkbox stuff or any other thing it is just grid view and then I came to my fragment. I've seen many of the people making a separate checkbox for doing there code. – Alok Jul 21 '17 at 10:21
  • can u show me what kind of output(design) you want? – Surender Kumar Jul 21 '17 at 10:52
  • okay done! I'll just do it in the edit section! Thanks for the help by the way... – Alok Jul 21 '17 at 11:06
  • @SurenderKumar I've added an edit section for you. Please have a look at it and give an idea on how to do that! – Alok Jul 21 '17 at 11:23
  • So for this firstly you need to create one custom drawable with that orange border and whenever user click on video thumbnail that time u need to set that background to ImageView else set transparent background. Whenever user clicks on image that time you need to put the code given in this [link](http://www.androhub.com/android-listview-checkbox/). This is an example of ListView with checkbox but same you can use for your concept but instead of checking checkbox u need to change imageview background. – Surender Kumar Jul 21 '17 at 11:33
  • You mean to say in drawable I have to make a selector an then add this is in a background of that! and what about the data that has to be passed from fragment to the activity? – Alok Jul 21 '17 at 11:38
  • While selecting imageViews you need to store them in some variable to access it later. After your selection finishes you need to use that variable to pass the data. – Surender Kumar Jul 21 '17 at 11:40
  • okay i'll set the border in drawable and same I'd reflect in the grid.onSelectedListener but in order to remove the border when user deselects that video what to do? – Alok Jul 21 '17 at 11:46
  • For that i shared u that Listview with CheckBox Link, it will be the same logic of checking and unchecking checkbox. – Surender Kumar Jul 21 '17 at 11:49
  • okay will do that stuff. I was trying to put the background in the gridView.setOnClickListener as list.get(position).setBackground but I'm not getting any method named as detBackground. Will see then! Thanks for the help – Alok Jul 21 '17 at 11:52

0 Answers0