MAOL MAOL - 7 months ago 56
Android Question

How to get context of the implemented callback inside a method of a fragment

I've defined the next header for a Fragment:

public class AllVideosFragment extends Fragment implements AutomaticCallback{

Inside of this Fragment, I have the next function to handle a spinner:

// Listener called when spinner item selected
spinnerLanguages.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parentView, View v, int position, long id) {
// Get selected row data to show on screen
String language = ((TextView) v.findViewById(;

Hawk.put(Config.TV_LANGUAGE, "en");
Hawk.put(Config.TV_LANGUAGE, "es");

//We need to retrive data again
new AutomaticRequest().getLives(String.valueOf(Hawk.get(Config.TV_LANGUAGE)), **CONTEXT OF THE CALLBACK**);

public void onNothingSelected(AdapterView<?> parentView) {
// your code here


If I would have the method outside of the spinner handle method, I could use "this", but inside I don't know what I need to use.

new AutomaticRequest().getLives(String.valueOf(Hawk.get(Config.TV_LANGUAGE)), this);

Which method I need to call in replacement of "this"?

Thank you for your help.


You are in an anonymous scope and this will refer to the scope. If you want to pass an outer this you have to explicitly name it in this case