更改方法的第二个参数' YoutubeRecyclerAdapter'来自' Context'到'回拨< ...>'

时间:2016-05-06 05:48:00

标签: java android android-recyclerview adapter

我遇到问题,使用RecyclerView,使用自定义适配器类进行改造,获取:

Change 2nd parameter of method 'VideoRecyclerAdapter' from 'Context' to 'Callback<ArrayList<VideoPojo>>'

Adapter.java:

public VideoRecyclerAdapter(ArrayList<VideoPojo> personList, Context context) {
        mPersonList = personList;
        mPref = context.getSharedPreferences("person", Context.MODE_PRIVATE);
        mEditor = mPref.edit();
    }

Activity.java:

videoAPI.getData(strJSON, new Callback<ArrayList<VideoPojo>>() {
        @Override
        public void success(ArrayList<VideoPojo> videoPojoList, Response response) {

            try {
                videoList = videoPojoList;
                videoAdapter = new VideoRecyclerAdapter(videoList, this);
                recyclerView.setAdapter(videoAdapter);

            } catch (Exception e) {

            }

        }

    });

API.java:

public interface VideoAPI {

    @GET("/list/{name}")
   void getData(@Path("name") String name, Callback<ArrayList<VideoPojo>> response);

}

1 个答案:

答案 0 :(得分:3)

只需更改此行

即可
videoAdapter = new VideoRecyclerAdapter(videoList, this);

videoAdapter = new VideoRecyclerAdapter(videoList, YourActivity.this);
内部界面 被称为Callback<ArrayList<VideoPojo>>。您需要ApplicationActivity 上下文