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

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;

}

  }


月关宝盒
浏览 69回答 2
2回答

紫衣仙女

尝试将 空设置为adapterrecyclerViewonCreateView()@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Bundle savedInstanceState) {&nbsp; &nbsp; // Inflate the layout for this fragment&nbsp; &nbsp; View v = inflater.inflate(R.layout.fragment_redirect, container, false);&nbsp; &nbsp; recylcerView =(RecyclerView) v.findViewById(R.id.recyclerView);&nbsp; &nbsp; LinearLayoutManager manager = new LinearLayoutManager(getContext());&nbsp; &nbsp; recylcerView.setLayoutManager(manager);&nbsp; &nbsp; recylcerView.setHasFixedSize(true);&nbsp; &nbsp; searchList = new ArrayList<>();&nbsp; &nbsp; List<Search> searchList = new ArrayList<>()&nbsp; &nbsp; SearchAdapter adapter1 = new SearchAdapter(getContext(),searchList);&nbsp; &nbsp; recylcerView.setAdapter(adapter1);&nbsp; &nbsp; loadSearch();&nbsp; &nbsp; return v;}然后在您向呼叫中添加新项时作为响应searchListadapter1.notifyDataSetChanged()

牛魔王的故事

尝试更改public&nbsp;class&nbsp;redirectFragment&nbsp;<recyclerView>&nbsp;extends&nbsp;Fragment进入这个public&nbsp;class&nbsp;redirectFragment&nbsp;extends&nbsp;Fragment
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java