Android:ImageView,带有网格视图中的复选框

时间:2015-10-28 10:20:21

标签: android gridview checkbox imageview

我正在尝试使用支票簿删除图像。

我已经完成删除所选的多个图像,这些图像是在按钮点击事件的网格视图中检查的。但是复选框出现在网格视图中。

如何删除带图像的复选框?

先谢谢。

这是我在Android中的getView()方法中的复选框代码

 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;
        }
    }

0 个答案:

没有答案