android-studioandroid-recyclerviewandroid-emulatoradapterlistitem

How to display listItem on emulator on recyclerview?


what I am trying to do is show a custom card in a recyclerview.

I can see it on the design view on android studio, but no when the emulator runs.

I just need to display de listItem.

Is is posible? if so, any help or suggestion would be great, thanks.

    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rcvPoolVariables"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="22dp"
            android:layout_marginStart="17dp"
            android:layout_marginEnd="17dp"
            tools:listitem="@layout/row_pool_objectives"
            app:layout_constraintTop_toBottomOf="@+id/containerVariableAndWeeks"
            app:layout_constraintBottom_toBottomOf="parent"/>

Solution

  • 1.xml

     <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/categoryview"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
                    app:spanCount="2"
                    tools:listitem="@layout/innercategorylist">
    
      </androidx.recyclerview.widget.RecyclerView>
    

    2.java file

    CategoryModel[] myListData1 = new CategoryModel[]{
                new CategoryModel( R.drawable.kiwi,"kiwi"),
                new CategoryModel(R.drawable.watermelon,"watermelon" ),
                new CategoryModel(R.drawable.strawberry,"strawberry")
    
        };
    innerCategoryAdapter = new InnerCategoryAdapter(myListData1, new InnerCategoryAdapter.HomeAdapterInterface() {
                @Override
                public void onRowClick(int searchText) {
                }
            });
    

    3.Adapter class id define and assign and model class to variable getter setter set