mercredi 28 octobre 2015

Android : ImageView with checkbox in grid-view

I am trying to delete images with Checkbook.

I have done to delete the selected multiple images which is checked from grid-view on button click event. But the check-boxes are appearing as they are in the grid-view .

How can I remove the check-boxes also with images?

Thanks in advanced.

Here is my check-box code in getView() method in Android

 class GridView_Adapter extends BaseAdapter {

        private LayoutInflater mInflater;
        SparseBooleanArray mSparseBooleanArray;
        public GridView_Adapter() {
            mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mSparseBooleanArray = new SparseBooleanArray();
        }

        public ArrayList<String> getCheckedItems() {
            ArrayList<String> mTempArry = new ArrayList<String>();

            for(int i=0;i<fileName.size();i++) {
                if(mSparseBooleanArray.get(i)) {
                    mTempArry.add(fileName.get(i));
                }}
            return mTempArry;
        }

        public int getCount() {
            return fileName.size();
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent)
        {
           ViewHolder holder;
            if (convertView == null)
            {
                holder = new ViewHolder();
                convertView = mInflater.inflate(R.layout.add_post_grid_item_layout, null);
                holder.image = (ImageView) convertView.findViewById(R.id.image);
                holder.checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox);
                convertView.setTag(holder);
            }
            else
            {
                holder = (ViewHolder) convertView.getTag();
            }

            Bitmap myBitmap = BitmapFactory.decodeFile(fileName.get(position));
            holder.image.setImageBitmap(myBitmap);
            final int pos = position;

            holder.checkbox.setId(position);
            holder.checkbox.setTag(position);
            holder.checkbox.setChecked(mSparseBooleanArray.get(position));
            holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
                 {
                     mSparseBooleanArray.put((Integer) buttonView.getTag(), isChecked);
                     int pos = (Integer) buttonView.getTag();
                     if (!buttonView.isChecked())
                     {
                         picsName.remove((String) fileName.get(pos));
                     }
                     else if(buttonView.isChecked())
                     {
                         if (!picsName.contains((String) fileName.get(pos)))
                         {
                             picsName.add((String) fileName.get(pos));
                         }
                     }
                     notifyDataSetChanged();
                 }
             });

            return convertView;
        }

               class ViewHolder
        {
            ImageView image;
            CheckBox checkbox;
            int id;
        }
    }




Aucun commentaire:

Enregistrer un commentaire