CheckBox取消隐藏在GridView上

时间:2015-09-29 20:24:18

标签: android

我确实将我的复选框可见性设置为" Gone" ,在我的xml文件中,我想在我的GridView上使用OnItemLongListnere时取消隐藏它,换句话说,如果我的gridView中有8个图片,我想取消隐藏每张照片的CheckBox!感谢

我的GridViewAdapter

 public class GridViewAdapter extends BaseAdapter {
// Declare variables
ImageView image;
private Activity activity;
private String[] filepath;
private String[] filename;

private static LayoutInflater inflater = null;

public GridViewAdapter(Activity a, String[] fpath, String[] fname) {
    activity = a;
    filepath = fpath;
    filename = fname;
    inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}


public int getCount() {
    return filepath.length;

}

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

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


public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)
        vi = inflater.inflate(R.layout.gridview_item, null);
    // Locate the TextView in gridview_item.xml
    TextView text = (TextView) vi.findViewById(R.id.text);
    // Locate the ImageView in gridview_item.xml
     image = (ImageView) vi.findViewById(R.id.grid_image);

    // Set file name to the TextView followed by the position
    File file = new File(filepath[position]);
    Picasso.with(activity).load(file).placeholder(R.drawable.rtrt).fit().centerCrop().into(image);


    // Decode the filepath with BitmapFactory followed by the position


    // Set the decoded bitmap into ImageView
  //  image.setImageBitmap(bmp);
    return vi;
}

}

2 个答案:

答案 0 :(得分:0)

从适配器中的gridview_item布局获取复选框引用,并设置其可见性View.VISIBLE。 在gridview_item布局的父布局上设置onlongclicklistener。

答案 1 :(得分:0)

也许这可以帮到你。

public class GridViewAdapter extends BaseAdapter {
        // Declare variables

        private Activity activity;
        private String[] filepath;
        private String[] filename;

        private static LayoutInflater inflater = null;

        public GridViewAdapter(Activity a, String[] fpath, String[] fname) {
            activity = a;
            filepath = fpath;
            filename = fname;
            inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        public int getCount() {
            return filepath.length;
        }

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

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

        public View getView(int position, View convertView, ViewGroup parent) {
            final Holder holder;

            if (convertView == null) {
                holder = new Holder();
                convertView = inflater.inflate(R.layout.gridview_item, null);
                holder.image = (ImageView) convertView.findViewById(R.id.grid_image);
                holder.text = (TextView) convertView.findViewById(R.id.text);
                holder.ck = (CheckBox) convertView.findViewById(R.id.checkbox);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }

            // Set file name to the TextView followed by the position
            File file = new File(filepath[position]);
            holder.ck.setVisibility(View.GONE);
            Picasso.with(activity).load(file).placeholder(R.drawable.rtrt).fit().centerCrop().into(holder.image);
            return convertView;
        }

        class Holder {
            ImageView image;
            TextView text;
            CheckBox ck;
        }
    }

和GridView LongClick

gridview.setOnItemLongClickListener(new OnItemLongClickListener() {

    public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
            int position, long arg3) {
        CheckBox ck = (CheckBox)arg1.findViewById(R.id.checkbox);
        ck.setVisibility(View.VISIBLE);
        return true;
    }
});