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: 
Make a new constructor and an instance variable:

```
AdapterInterface buttonListener;

public MyListAdapter (Context context, Cursor c, int flags, AdapterInterface buttonListener)
{
  super(context,c,flags);
  this.buttonListener = buttonListener;
}

```

When the Adapter is made, the instance variable will be given the proper reference to hold.

To call the Fragment from the click:

```
public void onClick(View v) {
   buttonListener.buttonPressed();
}

```

When making the `Adapter`, you will have to also pass your Fragment off to the Adapter. For example

```
MyListAdapter adapter = new MyListAdapter (getActivity(), myCursor, myFlags, this);

```

since `this` will refer to your Fragment, which is now an `AdapterInterface`.

Keep in mind that on orientation of the Fragment changes, it will most likely be recreated. If your Adapter isn't recreated, it can potentially keep a reference to a nonexistent object, causing errors.
a solution for NPE is first to make conctractor in your Fragment like that

```
public MyFragment MyFragment(){
        return this;
    }

```

then initialize your listener is adapter like that 

```
Lisener lisener = new MyFragment();

```