通过改造将arraylist数据传递到自定义适配器

问题描述

我有一个返回一些数据的服务,我已经可以用toast来获取此数据,但是我想将其包含在ArrayList中以供我的自定义适配器读取,有一个示例我使用了虚拟静态数据,但是我我不知道从改造获得数据后如何存储它。

HomeFragment

// dummy data
public static ArrayList<Content> initContents() {
    ArrayList<Content> listContent = new ArrayList<>();
    listContent.add(new Content("Cinque Terre","The coastline,the five villages in Italy.","https://2.bp.blogspot.com/-lYvUYANw3HQ/XY6etG5U8ZI/AAAAAAAAOlc/7uOsI_lFpiwVUE5un1QXJpfm0WPc3_bYQCLcBGAsYHQ/s1600/REG%2BBANNER%2Bok.png"));
    listContent.add(new Content("Paris","Paris is the capital city of France","https://3.bp.blogspot.com/-GsQJ555D954/XY6evcg32PI/AAAAAAAAOlg/RwJ6XUmnVP8bdIG8uXMyZd5eE6OfRsf1gCLcBGAsYHQ/s1600/TURKI%2BBANNER%2B%2Bok.png"));
    listContent.add(new Content("Rio de Janeiro","Rio has been one of Brazil's most popular destinations.","https://1.bp.blogspot.com/-gwSceqp5aUc/XY6ex9k86mI/AAAAAAAAOlk/NDk2TJqPX3cGhbmqDFRZx5nX7Fqsqui-wCLcBGAsYHQ/s1600/BANNER%2BDUBAI%2Bok.png"));
    listContent.add(new Content("Sydney","Sydney is the state capital of New South Wales.","https://2.bp.blogspot.com/-lYvUYANw3HQ/XY6etG5U8ZI/AAAAAAAAOlc/7uOsI_lFpiwVUE5un1QXJpfm0WPc3_bYQCLcBGAsYHQ/s1600/REG%2BBANNER%2Bok.png"));

    return listContent;
}

public ArrayList<Slider> initSliders() {

    return slideModels();
}

//my retrofit method
    ApiInterface apiInterface = ApiClient.create();
    final Call<SliderResponse> sliderCall;
    sliderCall = apiInterface.getSlider("Bearer " + token);
    sliderCall.enqueue(new Callback<SliderResponse>() {
        @Override
        public void onResponse(Call<SliderResponse> call,Response<SliderResponse> response) {
            Toast.makeText(getContext(),response.body().getData().get(0).getImage(),Toast.LENGTH_SHORT).show();
            if (response.body() != null) {
                Toast.makeText(getContext(),"Getting slider data",Toast.LENGTH_SHORT).show();
                if (response.body().getData() != null) {
                    Toast.makeText(getContext(),Toast.LENGTH_SHORT).show();
                    slideModels = response.body().getData();
                } else {
                    Toast.makeText(getContext(),"Fail getting data",Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(getContext(),"Fail slider data",Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFailure(Call<SliderResponse> call,Throwable t) {

        }
    });

ItemGroupAdapter

// trying with public arraylist
private void sliderView(SliderViewHolder holder) {
    SliderAdapter sliderAdapter = new SliderAdapter(context,homeFragment.initSliders());
    holder.svImage.setIndicatorAnimation(IndicatorAnimationType.WORM); //set indicator animation by using SliderLayout.IndicatorAnimations. :WORM or THIN_WORM or COLOR or DROP or FILL or NONE or SCALE or SCALE_DOWN or SLIDE and SWAP!!
    holder.svImage.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
    holder.svImage.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_BACK_AND_FORTH);
    holder.svImage.setIndicatorSelectedColor(Color.WHITE);
    holder.svImage.setIndicatorUnselectedColor(Color.GRAY);
    holder.svImage.setScrollTimeInSec(3);
    holder.svImage.setAutoCycle(true);
    holder.svImage.startAutoCycle();
    holder.svImage.setSliderAdapter(sliderAdapter);
}

//ex
private void menuView(MenuViewHolder holder){
    MenuAdapter menuAdapter = new MenuAdapter(context,initMenus());
    holder.rvList.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false));
    holder.rvList.setAdapter(menuAdapter);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)