First of all, you have to set the event and use it in your activity... you will have to modify your adapter and add to it an OnClickListener
attr:
private Context context;
private OnClickListener listener;
ArrayList<Bitmap> arrayList;
ImageButton i1;
//Constructor to initialize values
public CustomGridAdapter(Context context, ArrayList<Bitmap> ob, OnClickListener listener) {
arrayList = ob;
this.context = context;
this.listener = listener;
}
And then to set your setOnClickListener
, you have to do the following:
imageView.setImageBitmap(arrayList.get(position));
ImageButton imageButton = (ImageButton) gridView
.findViewById(R.id.imageButton);
imageButton.setOnClickListener(listener);
Then, in your java, you need to let your activity implements OnClickListener, and then override the onClickListener method, where you can use the following method to reload your list:
@Override
public void onClick(View v) {
adapter = new CustomGridAdapter(MyActivity.this, myArrayListWithMyData, MyActivity.this);
listView.setAdapter(adapter);
listView.invalidate();
}
To set the adapter, you can pass your context (this
, for example) as argument for the OnClickListener
:
adapter = new CustomGridAdapter(this, myArrayListWithMyData, this);
Hope it helps!