3 回答
TA贡献1827条经验 获得超4个赞
我发现我的错误在于我将数据发送到 recyclerView 感谢所有帮助我的人,这对我来说是正确的
RecyclerViewAdapterDistance_Map recyclerViewAdapterDistanceMap = new RecyclerViewAdapterDistance_Map(jCars, cntx,false);
mrecyclerView.setAdapter(recyclerViewAdapterDistanceMap);
RecyclerViewAdapterDistance_Map recyclerViewAdapterDistanceMap2 = new RecyclerViewAdapterDistance_Map(cntx, fromDate, fromTime, toDate, toTime, distance, jCars,false);
mrecyclerView.setAdapter(recyclerViewAdapterDistanceMap2);
mrecyclerView.setLayoutManager(new LinearLayoutManager(cntx));
然后在片段中
FragmentActivity fragmentRow = getActivity();
FragmentManager fragmentManager = fragmentRow.getSupportFragmentManager();
Fragment listFragment = fragmentManager.findFragmentById(R.id.carsList);
DistanceReportLists distanceReportLists = new DistanceReportLists().newInstance(jcar, cntx, edtFromDate.getText().toString(), tvFromTime.getText().toString(), edtToDate.getText().toString(), tvToTime.getText().toString(), String.valueOf(distance));
FragmentTransaction transaction = fragmentRow.getSupportFragmentManager().beginTransaction();
if (listFragment != null) {
transaction.remove(listFragment);
}
transaction.replace(R.id.fragment_list, distanceReportLists);
transaction.commit();
TA贡献1877条经验 获得超6个赞
将布局参数设置为 recyclerview。
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams
(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
recyclerView.setLayoutParams(params);
有关详细说明,请访问此链接 NullPointerException - Attempt to invoke virtual method RecyclerView$ViewHolder.shouldIgnore()' on a null object reference
或者
尝试在活动中使用 findViewById() 绑定您的回收站视图。
RecyclerView mRecyclerView= view.findViewById(R.id.recycler_view)// recycler_view is the id of RecyclerView in XML file.
添加回答
举报