0

I have an Activity which implements two interfaces for call backs on certain actions. I want to send a context of my Activity to another Class which will access the object of the specified callback.

Here is my code :-

     public class OpenSchoolFragment extends Fragment implements IOpenSchoolCallBack, INetworkCallback
    {
// 1st case
       expandableListAdapter = new AdapterOpenSchool(getActivity(), this); // IOpenSchoolCallBack should provided

//2nd case
call.enqueue(new Callback<OpenSchool>()
        {
            @Override
            public void onResponse(Call<OpenSchool> call, Response<OpenSchool> response)
            {

                if (response.isSuccessful())
                {
                    OpenSchool userBatch = response.body();
                    if (userBatch != null)
                    {
                        RLProgressRoot.setVisibility(View.GONE);
                    }
                }
                else
                {
                    RLProgressRoot.setVisibility(View.GONE);
                    if (response.code() == getResources().getInteger(R.integer.integer_404))
                    {
                        DialogHelperUtil.showRetrySnackbar(RLContainer, getString(R.string.str_error_unauthorised),this); //INetworkCallBack should be provided

                    }
                    else
                    {
                        DialogHelperUtil.showMessageSnackbar(RLContainer, response.raw().message());
                    }
                }
            }

        }

So when I try to pass "this" in the second case, I get an error saying :-

Wrong 3rd argument type. Found: 'Callback<OpenSchool>', required: 'INetworkCallback'

How can I make sure the right callback is passed in "this" for the second case ie. INetworkCallback?

user3034944
  • 1,541
  • 2
  • 17
  • 35

1 Answers1

1

The "this" refers to the current object in which you are in that precise point.

If your DialogHelperUtil.showRetrySnackbar() is called from Callback class, then this refers to Callback.

You can "exit" current inner-Class (Callback) and reach its outer-class by using OuterClass.this

Michael
  • 41,989
  • 11
  • 82
  • 128
emandt
  • 2,547
  • 2
  • 16
  • 20