My RecyclerView
does not call onCreateViewHolder
, onBindViewHolder
even MenuViewHolder
constructor, therefore nothing app
Your getItemCount
method returns 0
. So RecyclerView
never tries to instantiate a view. Make it return something greater than 0
.
for example
@Override
public int getItemCount() {
return data.size();
}
Please do the following thing
@Override
public int getItemCount() {
return data.size();
}
recyclerView.setAdapter(adapter); called The recyclerView list is populated by calling the method.
Another one is make sure you set layout manager to RecyclerView:
recycler.setLayoutManager(new LinearLayoutManager(this));
In my case after changing Activity to use ViewModel and DataBinding, I had forgotten to remove setContentView
method calling from onCreate
method. By removing it my problem solved.
Make sure your XML
and Koltin/Java
code match. In my case, I had a problem with the ViewHolder
since I had written:
var txt: AppCompatTextView = itemView.findViewById(R.id.txt)
But since my XML code is:
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.../>
I had to change the privious row into:
var txt: TextView = itemView.findViewById(R.id.txt)
In addition, I also had to remove:
recyclerView.setHasFixedSize(true);
I hope this can help you :)