Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple selectable GridView

Tags:

android

OK, so I think I've exhausted searching for this question, and it's either that I'm totally missing something or nobody else has tried to create a GridView (showing images) which allows the user to select multiple images. Basically I want to have the orange selection box appear whenever a user selects an image, or disappear if the user has already chosen the image.

Is this something that I'll have to roll myself with a customer View? I may also try including a CheckBox with each image and have the CheckBox selected if the image is.

Any assistance would be greatly appreciated.

  • michael
like image 973
mmaitlen Avatar asked Jul 28 '09 00:07

mmaitlen


3 Answers

Have a look at this example -- they use a custom layout class that implements Checkable interface and set a colored background-drawable on checked items.

like image 87
Ridcully Avatar answered Oct 09 '22 06:10

Ridcully


I have used an excellent code by Mihai Fonoage.

And then:

  1. added a selected flag to LoadedImage class,
  2. in the onItemClick() function I mark the clicked item as selected
  3. in the adapter's getView() use the flag to i.e. set the image background

IT WORKS.

like image 37
Yar Avatar answered Oct 09 '22 05:10

Yar


Just draw a checkbox onto the cell's bitmap when selected. Draw the original when toggle unchecked.

  private Bitmap drawCheck(Bitmap bmp)
  {
   Bitmap bmChecked = Bitmap.createBitmap(bmp.getWidth(),     bmp.getHeight(), bmp.getConfig());
   Bitmap check = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.upcheck);
   Canvas canvas = new Canvas(bmChecked);

   canvas.drawBitmap(bmp, 0, 0, null);
   canvas.drawBitmap(check, 0, 0, null); 
   return bmChecked;
  }
like image 34
Rob Avatar answered Oct 09 '22 06:10

Rob