darsh2 / MultipleImageSelect

Android library that provides for multiple image selection.
Apache License 2.0
300 stars 112 forks source link

Is it possible to stop user to select images more than limit #8

Closed ahmadplero closed 8 years ago

ahmadplero commented 9 years ago

Hi darsh,

For now, we have an option to set a limit for user image selection. In this case, user can select no of images more than limit but toast show to user to unselect images that are more than limit but I want to make user unable to select images more than limit. Is it possible?

thanks..

darsh2 commented 9 years ago

Yes it is possible to do so. In the ImageSelectActivity class, in the toggleSelection(int position) make the following changes:

private void toggleSelection(int position) {
    if (!images.get(position).isSelected && countSelected == Constants.limit) {
        Toast.makeText(getApplicationContext(), String.format(getString(R.string.limit_exceeded), Constants.limit), Toast.LENGTH_LONG).show();
        return;
    }

    images.get(position).isSelected = !images.get(position).isSelected;
    if (images.get(position).isSelected) {
        countSelected++;
    } else {
        countSelected--;
    }
    customImageSelectAdapter.notifyDataSetChanged();
}

I'll add this soon. Thanks for this feature suggestion.