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

android.support.v7.widget.RecyclerView$ViewHolder

android.support.v7.widget.RecyclerView$ViewHolder

慕森卡 2021-05-31 15:35:47
当我想将一些新数据设置到我的RecyclerView. firsTime它的OK,但是当我想刷新我RecyclerView(在我的代码段其他)出现此错误。我知道此错误将用于RecyclerView.Animation并查看此代码: RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();  if (animator instanceof SimpleItemAnimator) {       ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);  }我把这段代码放在我的片段中onCreateView,对不起,我的问题没有解决。谁能告诉我出了什么问题?谢谢。public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {    View view = inflater.inflate(R.layout.fragment_distance_report_lists, container, false);    RecyclerView recyclerView = new RecyclerView(view.getContext());    //((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);    RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();   if (animator instanceof SimpleItemAnimator) {        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);    }    if (TextUtils.isEmpty(distance)) {        recyclerView.setAdapter(new RecyclerViewAdapterDistance(jCars, cntx));        recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));    } else {        recyclerView.setAdapter(new RecyclerViewAdapterDistance(cntx, fromDate, fromTime, toDate, toTime, distance, jCars));        recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));    }    return recyclerView;}
查看完整描述

3 回答

?
GCT1015

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();


查看完整回答
反对 回复 2021-06-02
?
慕哥9229398

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.



查看完整回答
反对 回复 2021-06-02
  • 3 回答
  • 0 关注
  • 423 浏览

添加回答

举报

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