Question: I'm looking at the `ss` command code and I've seen a function that seems to be passing a function as an argument to another function. But I thought that the way of doing this was declaring a pointer to a function. In the code instead they do the as follow:

```
generic_record_read(fp, tcp_show_line, f, AF_INET6).

```

The prototype of that function is:

```
static int generic_record_read(FILE *fp,
               int (*worker)(char*, const struct filter *, int),
               const struct filter *f, int fam);

```

and the function I think is being passed as a parammeter to `generic_record_read` is `tcp_show_line`, which prototype is:

```
static int tcp_show_line(char *line, const struct filter *f, int family)

```

I do not understand the way of declaring the parmeter `tcp_show_line` in `generic_record_read` as `int (*worker)(char*, const struct filter *, int)`

The types (`char*, const struct filter *, int`) correspond with the parameters of `tcp_show_line` but with `int (*worker)` preceding.

All seems that this is a way of passing a function as a parameter because in the implementation of `generic_record_read`, *worked* is used as if it was the function `tcp_show_line`, but I've never seen something like this:

```
static int generic_record_read(FILE *fp,
               int (*worker)(char*, const struct filter *, int),
               const struct filter *f, int fam)
{
//....

    if (worker(line, f, fam) < 0)
        return 0;
//.....
}

```

Am I wrong?

Answer: 
Follow the 2 steps below for receive callback from `Adapter` in `Fragment (or Activity)`

**First:** In your `Adapter`

```
public class ListAdapter extends RecyclerView.Adapter < RecyclerListAdapter.ItemViewHolder > {
    ...
    private ListAdapterListener mListener;

    public interface ListAdapterListener { // create an interface
        void onClickAtOKButton(int position); // create callback function
    }

    public RecyclerListAdapter(Context mContext, ArrayList < Items > listItems, ListAdapterListener mListener) { // add the interface to your adapter constructor
        ...
        this.mListener = mListener; // receive mListener from Fragment (or Activity)
    }
    ...
    public void onBindViewHolder(final ItemViewHolder holder, final int position) {

        holder.btnOK.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // use callback function in the place you want
                mListener.onClickAtOKButton(position);
            }
        });
        ...
    }
    ...
}

```

**Second:** In your `Fragment (or Activity)`, there are 2 ways for implement callback method 

*Way 1*

```
 public MyListFragment extends Fragment {
     ...
     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
         ...
         ListAdapter adapter = new ListAdapter(getActivity(), listItems, new ListAdapter.ListAdapterListener() {
             @Override
             public void onClickAtOKButton(int position) {
                 Toast.makeText(getActivity(), "click ok button at" + position, Toast.LENGTH_SHORT).show();
             }
         });
         ...
     }
 }

```

*Way 2*

```
public MyListFragment extends Fragment implements ListAdapter.ListAdapterListener {
     ...
     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        ListAdapter  adapter = new ListAdapter (getActivity(), listItems, this);
        ...   
    }

    @Override
    public void onClickAtOKButton(int position) {  
        Toast.makeText(getActivity(), "click ok button at" + position, Toast.LENGTH_SHORT).show();     
    }          
}

```
Make a constructor like that:

```
  public MyAdapter(Activity activity,AlertMessageBoxOk alertMessageBoxOk) {

  this.mActivity = activity;

  mAlertMessageBoxOk = alertMessageBoxOk;

}

```

call the interface from adapter use any event

```
mAlertMessageBoxOk.onOkClick(5);

```

after that implement AlertMessageBoxOk interface to your fragment like this,

```
class MyFragment extends Fragment implements AlertMessageBoxOk {

@Override
public void onOkClick(int resultCode) {

  if(resultCode==5){

  enter code here 

      }
    } 
 }

```