Recyclerview not call onCreateViewHolder

前端 未结 30 1364
离开以前
离开以前 2020-11-28 07:04

My RecyclerView does not call onCreateViewHolder, onBindViewHolder even MenuViewHolder constructor, therefore nothing app

相关标签:
30条回答
  • 2020-11-28 07:48

    I had the same problem, because I was using android.support.constraint.ConstraintLayout in layout resource. Changing to FrameLayout helped.

    0 讨论(0)
  • 2020-11-28 07:49

    I really really hope this helps someone someday. I just spend over an hour on this one going nuts!

    I had this:

    projects_recycler_view.apply {
                this.layoutManager = linearLayoutManager
                this.adapter = adapter
            }
    

    When I should have had this:

    projects_recycler_view.apply {
                this.layoutManager = linearLayoutManager
                this.adapter = projectAdapter
            }
    

    Because I foolishly called my adapter adapter, it was being shadowed by the recycler view's adapter in the apply block! I renamed the adapter to projectAdapter to differentiate it and problem solved!

    0 讨论(0)
  • 2020-11-28 07:49

    Setting the height of the TextView in the custom.xml or RecyclerView. If height is wrap-content, the RecyclerView will not be visible.

    0 讨论(0)
  • 2020-11-28 07:49

    This happened when my RecyclerView was inside a ScrollView and I was using Android Support Library 23.0. To fix, I updated to Android Support Library 23.2:

    In build.gradle:

    dependencies {
        ...
        compile 'com.android.support:appcompat-v7:23.2.+'
        compile 'com.android.support:cardview-v7:23.2.+'
    }
    
    0 讨论(0)
  • 2020-11-28 07:49

    I struggled with this issue for many hours. I was using a fragment. And the issue was not returning the view. Below is my code:

    ProductGridBinding binding = DataBindingUtil.inflate( inflater, R.layout.product_grid, container, false);
    
    
    
        mLinearLayoutManager = new LinearLayoutManager(getActivity());
        mLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    
        binding.rvNumbers.setHasFixedSize(true);
        binding.rvNumbers.setLayoutManager(mLinearLayoutManager);
        binding.rvNumbers.setAdapter(adapter);
    
    
        View view = binding.getRoot();
    
    
        return view;
    
    0 讨论(0)
  • 2020-11-28 07:50

    In my case , I was missing calling notifyDataSetChanged() after setting list in adapter.

    public void setUserList(List<UserList> userList) {
          this.userList = userList;
            notifyDataSetChanged();
    }
    
    0 讨论(0)
提交回复
热议问题