多个界面实现Android [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我有一个Activity,它实现了两个接口,用于某些操作的回调。我想将我的Activity的上下文发送到另一个Class,它将访问指定回调的对象。

这是我的代码: -

     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());
                    }
                }
            }

        }

因此,当我尝试在第二种情况下传递“this”时,我得到一个错误说: -

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

如何确保在第二种情况下在“this”中传递正确的回调,即。 INetworkCallback

java android interface callback this
1个回答
1
投票

“this”指的是您处于该精确点的当前对象。

如果你的qazxsw poi是从qazxsw poi类调用的,那么qazxsw poi指的是DialogHelperUtil.showRetrySnackbar()

你可以通过使用Callback“退出”当前的内部类(this)并到达它的外部类

© www.soinside.com 2019 - 2024. All rights reserved.