android.support.v7.widget.RecyclerView$ViewHolder

当我想将一些新数据设置到我的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;

}


慕森卡
浏览 424回答 3
3回答

GCT1015

我发现我的错误在于我将数据发送到 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();

慕哥9229398

将布局参数设置为 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.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java