2

XML:

<androidx.recyclerview.widget.RecyclerView
   android:visibility="visible"
   android:id="@+id/itemshowRecylerview"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:listitem="@layout/singleitemforrecylerview"/>

Java Code:

itemshowRecylerview.setLayoutManager(new LinearLayoutManager(MainActivity.this));
        itemshowRecylerview.setHasFixedSize(true);

Viewholder Code:

 @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.singleitemforrecylerview, null,false);
        return new ItemDetailsAdapter.ViewHolder(view);
    }

enter image description here

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
abdul_kayuem
  • 49
  • 2
  • 8

2 Answers2

2

You need to change your custom adapter class, pass parent instead of null in your inflate method

@NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.singleitemforrecylerview, parent,false);
        return new ItemDetailsAdapter.ViewHolder(view);
    }
AkterUzzaman
  • 52
  • 2
  • 9
0

You have use this type of RecyclerView set orientation and layoutManager in RecyclerView and working code shown in below.

  <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/recyclerView"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
           app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                        app:spanCount="1">
                    </androidx.recyclerview.widget.RecyclerView>
       recyclerView.setAdapter(yourAdapter);
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
  • I used : recyclerView.setAdapter(yourAdapter); This line ! And changed also in layout. But, The problem is not changed ! Whatever, The probelm is solved by AkterUzzaman... – abdul_kayuem Jan 07 '21 at 05:32