Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,

前端 未结 8 1822
灰色年华
灰色年华 2020-12-01 08:54

my RecyclerView do not call onCreateViewHolder, onBindViewHolder, therefore, does not appear nothing in recyclerview. I put logs for debugging, and no log is shown. What can

相关标签:
8条回答
  • 2020-12-01 09:17

    In my case i had this structure

    <ScrollView>
        <RelativeLayout>
            <android.support.v7.widget.RecyclerView/>
    
        </RelativeLayout>
    </ScrollView>
    

    i solved the problem remove Relative

    <ScrollView>
    
            <android.support.v7.widget.RecyclerView/>
    
    </ScrollView>
    
    0 讨论(0)
  • 2020-12-01 09:20

    Is kind of silly, but another thing that can block the calls to the methods is to declare the visibility of the view as GONE.

    android:visibility="gone"
    
    recyclerView.setVisibility(View.GONE);
    

    Any of these will block the call of the methods in RecyclerView.Adapter

    I hope it can help someone.

    0 讨论(0)
  • 2020-12-01 09:23

    Might have been a different case but for me I just forgot to set the Layout Manager as follows:

    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recycler.setLayoutManager(layoutManager);
    

    Hope it helps :)

    0 讨论(0)
  • 2020-12-01 09:28

    Its late but hope it will help somone. try either of the following:

    first solution: make sure you haven't use this line unnecessarily

    recyclerView.setHasFixedSize(true);
    

    second solution: make sure you set layout manager to recyclerView

    recycler.setLayoutManager(new LinearLayoutManager(this));
    

    third solution: you getItemCount returns 0, So RecyclerView never tries to instantiate a view. Make it return something greater than 0

    0 讨论(0)
  • 2020-12-01 09:34

    If RecyclerView gets put into a ScrollView, then during measure step its height is unspecified (because ScrollView allows any height) and gets equal to minimum height (as per implementation) which is apparently zero.

    ref : android: RecyclerView inside a ScrollView

    Solution : - put views in row of RecyclerViews - Calculate the size of the list items and set the height of the ListView programmatically http://vardhan-justlikethat.blogspot.com/2014/04/android-listview-inside-scrollview.html

    0 讨论(0)
  • 2020-12-01 09:35

    In my Case I was using Fragment-> ViewPager and Tablayout -> Inside viewpagers item I used RecyclerView.

    So Instead of calling ViewPagerAdapter(getChildFragmentManager()) , I was calling ViewPagerAdapter(getSupportFragmentManager()) , that is why any of my recycler adapter item is not getting called.

    So proper way to set the ViewPagerAdapter within a fragment is

    ViewPagerAdapter(getChildFragmentManager())

    0 讨论(0)
提交回复
热议问题