我在我的片段中使用带有图像和复选框的自定义gridview,用户可以使用复选框选择图像,以下是我的带适配器的代码可以任何人告诉它有什么问题,提前感谢
问题
holder.img.setOnClickListener(new ImageClickListener(context, holder,thumbnailsselection));
holder.img.setImageResource(imageId[position]);
holder.tv.setChecked(thumbnailsselection[position]);
holder.id = position;
无法解析Imageclicklistner
Fragmentcode
public class ShareAFriend extends Fragment{
private int count;
private Bitmap[] thumbnails;
private boolean[] thumbnailsselection;
private String[] arrPath;
int[] flags = new int[]{
R.drawable.propicone,
R.drawable.propicone,
R.drawable.propicone,
R.drawable.propicone,
R.drawable.propicone,
R.drawable.propicone,
R.drawable.propicone,
R.drawable.propicone,
R.drawable.propicone
};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.share_a_friend, container, false);
GridView imagegrid = (GridView)rootView.findViewById(R.id.imageGrid);
// imageAdapter = new ImageAdapter();
imagegrid.setAdapter(new CustAdapter(getActivity(),flags));
return rootView;
}
public class CustAdapter extends BaseAdapter {
String[] result;
Context context;
int[] imageId;
private LayoutInflater inflater = null;
public CustAdapter(Context cont, int[] prgmImages) {
// TODO Auto-generated constructor stub
context = cont;
imageId = prgmImages;
inflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return result.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder {
CheckBox tv;
ImageView img;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder = new Holder();
View rowView;
rowView = inflater.inflate(R.layout.griditem, null);
holder.tv = (CheckBox) rowView.findViewById(R.id.grid_item_checkbox);
holder.img = (ImageView) rowView.findViewById(R.id.grid_item_image);
holder.tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CheckBox cb = (CheckBox) view;
int id = cb.getId();
if (thumbnailsselection[id]){
//cb.setChecked(false);
thumbnailsselection[id] = false;
} else {
//cb.setChecked(true);
thumbnailsselection[id] = true;
}
}
});
holder.img.setOnClickListener(new ImageClickListener(context, holder,thumbnailsselection));
holder.img.setImageResource(imageId[position]);
holder.tv.setChecked(thumbnailsselection[position]);
holder.id = position;
return rowView;
}
}
}