简体   繁体   English

如何引用实现接口的活动?

[英]How to to reference an activity that implements an interface?

It says wrong third argument, I've implemented LoaderManager.LoaderCallbacks in mainActivity. 它说了错误的第三个参数,我已经在mainActivity中实现了LoaderManager.LoaderCallbacks。

getSupportLoaderManager().initLoader(LOADER_ID,getUrlBundle(),this);

Why is this happening ? 为什么会这样呢?

    public class MainActivity extends AppCompatActivity implements MovieAdapter.movieAdapterClickHandler,LoaderManager.LoaderCallbacks<List<Movie>> {
    ...
@Override

        protected void onCreate(Bundle savedInstanceState) {
    ...


   getSupportLoaderManager().initLoader(LOADER_ID,getUrlBundle(),this);
    }
    ...

@Override
    public Loader<List<Movie>> onCreateLoader(int i, final Bundle bundle) {
        return new AsyncTaskLoader<List<Movie>>(this) {
            @Override
            protected void onStartLoading() {
                if(bundle==null)
                    return;
                progressBar.setVisibility(View.VISIBLE);
                errorMessage.setVisibility(View.INVISIBLE);
                forceLoad();

            }

            @Override
            public List<Movie> loadInBackground() {
                /* Extract the url from the args using our constant */
                String UrlString = bundle.getString(URL_EXTRA);

                /* If the user didn't enter anything, there's nothing to search for */
                if (UrlString == null || TextUtils.isEmpty(UrlString)) {
                    return null;
                }

                return QueryUtils.fetchMovieData(UrlString);
            }

            @Override
            public void deliverResult(List<Movie> data) {
                super.deliverResult(data);
            }
        };



    }

    @Override
    public void onLoadFinished(Loader<List<Movie>> loader, List<Movie> movies) {
        if (movies != null && !movies.isEmpty()) {
            movieAdapter.MovieAdapterUpdate(movies);
            progressBar.setVisibility(View.INVISIBLE);
        } else {
            progressBar.setVisibility(View.INVISIBLE);
            errorMessage.setText("No data returned");
            errorMessage.setVisibility(View.VISIBLE);

        }
    }


    @Override
    public void onLoaderReset(Loader<List<Movie>> loader) {

    }
    }

This can happen if you're using the wrong imports for the Loader classes that you're using. 如果对使用的Loader类使用了错误的导入,则可能会发生这种情况。 For example, if you're using 例如,如果您使用

import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;

along with 随着

import android.app.LoaderManager;

then you'll get the wrong third argument warning as you're mixing support dependencies with non-support dependencies. 那么在将支持依赖项与非支持依赖项混合在一起时,您会收到错误的第三个参数警告。 Whereas this would work: 鉴于此可行:

import android.support.v4.app.LoaderManager;

From Android Document Android文档

initLoader(int id, Bundle args, LoaderCallbacks<D> callback)

You need to pass the loader callback 您需要传递加载程序回调

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何指定实现接口的引用方法参数 - How To Specify a Reference Method Parameter that Implements an Interface 如果ViewModel拥有此Activity实现的接口引用,GC是否会收集Activity引用? - Will GC collect Activity reference if ViewModel holds interface reference which this Activity implements? 如果main_activity已经实现ActionBar.TabListener,如何在main_activity中的另一个类中实现接口 - How to implement an Interface in another class in main_activity if main_activity already implements ActionBar.TabListener 如何确保参数实现接口 - How to ensure an argument implements an interface 如何实现通用接口的方法? - How to implements a method of a generic interface? 如何通过他们实现的接口找到实例? - How to find the instance by the interface they implements? 如何传递实现接口的参数? - How to pass argument that implements a interface? 如果字段实现该接口,则如何实现该接口 - How to implement an interface if a field implements that interface 如何在实现接口但不扩展另一个类的Java类中引用super方法? - How can I reference a super method in a Java class that implements an interface but does not extend another class? 获取对从枚举类名实现接口的Java Enum的引用 - Get reference to Java Enum that implements an interface from enum class name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM