I have a custom gridview with checkbox, imageview and textview. In the gridviewAdapter.getView(), i have used rows and holder to initialise the values for checkbox, imageview and textview. Now when I click on checkbox, I need to fetch the position of that gridview item so i can move the image from its position to another position in a gridview.
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.imageTitle = (TextView) row.findViewById(R.id.textView);
holder.image = (ImageView) row.findViewById(R.id.imageView);
holder.cb=(CheckBox)row.findViewById(R.id.checkBox);
holder.cb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//here with this checkbox which just got clicked,
// i want to access its gridview position or holder index
// so i can get access to the image
}
});
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
ImageItem item = (ImageItem)dataArraylist.get(position);
holder.imageTitle.setText(item.getTitle());
holder.image.setImageBitmap(item.getImage());
// holder.cb.setChecked(item.isSelected());
return row;
}
public static class ViewHolder {
public TextView imageTitle;
public ImageView image;
public CheckBox cb;
}
Aucun commentaire:
Enregistrer un commentaire