. , setOnOptionsClickListener ( OnOptionsClickListener), , .
, Activity/Fragment
public interface OnOptionsClickListener {
void onOptionsClicked(View view, PictureItem item);
}
mAdapter= new MyGridAdapter();
mAdapter.setOnOptionsClickListener(new OnOptionsClickListener() {
public void onClick(View view, PictureItem item) {
}
});
public void setOnOptionsClickListener(OnOptionsClickListener l) {
mOnOptionsClickListener = l;
}
findViewById(R.id.btn_options).setOnClickListener(new OnClickListener(){
public void OnClick(View view) {
mOnOptionsClickListener.onOptionsClicked(view, currentPictureItem);
}
});
.. , OnClick() (, currentPictureItem, URL- ). OnClickListener.
Edit
So here is the explanation. Adapterserves for viewing GridViewfor View-provider. It creates views and sets up the base state. Therefore, during initialization of views, all clicks must be set to Adapter. Moreover, we do not want to have messy Activitywith a nested Adapter, but we want Adapter to be a separate class. For this reason, you usually need to create an additional interface in order to have access to the object currentItemto retrieve data.
source
share