我正在尝试显示一个基于recyclerview的列表,看到大量数据,我将处理大量数据,但是每当我尝试执行该应用程序时,它都会呈现,但我总是遇到此错误“ E / RecyclerView:未连接适配器;正在跳过布局。”
我已经遍历了网络中的大多数解决方案,但对我而言都不可行。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// if (getArguments() != null) {
// mParam1 = getArguments().getString(ARG_PARAM1);
// mParam2 = getArguments().getString(ARG_PARAM2);
// }
Person person1 = new Person("xx", "xx", "xx");
Person person2 = new Person("yy", "yy", "yy");
Person person3 = new Person("zz", "zz", "zz");
personList.add(person1);
personList.add(person2);
personList.add(person3);
mContext= getContext();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View personListView = inflater.inflate(R.layout.fragment_list_person, container, false);
personRecyclerView = personListView.findViewById(R.id.personRecyclerView);
personRecyclerViewAdapter = new PersonListRecyclerAdapter(mContext, personList);
personRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
// recyclerViewLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
personRecyclerView.setHasFixedSize(true);
return personListView;
}
我看不到我所缺少或存在的问题,有什么线索解决吗?enter code here
答案 0 :(得分:2)
它要求您分配一个RecyclerView.Adapter
:
personRecyclerView.setAdapter(personRecyclerViewAdapter);
答案 1 :(得分:1)
您需要告诉RecyclerView
您要使用哪个适配器来获取数据。这是通过setAdapter()
方法(see docs)完成的:
personRecyclerView.setAdapter(personRecyclerViewAdapter);