为了账号安全,请及时绑定邮箱和手机立即绑定

回收器视图适配器未使用片段附加

回收器视图适配器未使用片段附加

月关宝盒 2022-09-22 15:48:01

im试图从数据库检索数据到碎片使用回收视图,但我得到错误回收审查:没有适配器连接;跳过布局


我试图在获取和获取上下文之间切换,但仍然没有解决任何问题


搜索.java


package com.example.lifetravel40;


public class Search {


private  int search_id;

private String activity;

private String description;

private String activity_img;

private String origin;

private String destination;

private String date_from;

private String date_to;

private String price ;


public Search(String activity, String description, String activity_img, String origin, String destination, String date_from, String date_to, String price){


    this.search_id = search_id;

    this.activity = activity;

    this.description = description;

    this.activity_img = activity_img;

    this.origin =origin;

    this.destination = destination;

    this.date_from = date_from;

    this.date_to = date_to;

    this.price = price;

}


public int getSearch_id(){

    return search_id;

}


public String getActivity(){

    return activity;

}



public String getDescription(){

    return description;

}



public String getActivity_img(){

    return activity_img;

}



public String getOrigin(){

    return origin;

}


public String getDestination(){

    return destination;

}



public String getDate_from(){

    return date_from;

}



public String getDate_to(){

    return date_to;

}



public String getPrice(){

    return price;

}

  }


查看完整描述

2 回答

?
紫衣仙女

TA贡献1496条经验 获得超16个赞

尝试将 空设置为adapterrecyclerViewonCreateView()


@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

                         Bundle savedInstanceState) {

    // Inflate the layout for this fragment

    View v = inflater.inflate(R.layout.fragment_redirect, container, false);


    recylcerView =(RecyclerView) v.findViewById(R.id.recyclerView);

    LinearLayoutManager manager = new LinearLayoutManager(getContext());

    recylcerView.setLayoutManager(manager);

    recylcerView.setHasFixedSize(true);


    searchList = new ArrayList<>();




    List<Search> searchList = new ArrayList<>()

    SearchAdapter adapter1 = new SearchAdapter(getContext(),searchList);

    recylcerView.setAdapter(adapter1);

    loadSearch();


    return v;


}

然后在您向呼叫中添加新项时作为响应searchListadapter1.notifyDataSetChanged()


查看完整回答
反对 回复 4天前
?
牛魔王的故事

TA贡献1500条经验 获得超3个赞

尝试更改

public class redirectFragment <recyclerView> extends Fragment

进入这个

public class redirectFragment extends Fragment


查看完整回答
反对 回复 4天前

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信