How to use Sample Data in android Recylerview
Sample
data is a set of model data to help the developer to see the design without a run
the code into the device and also does not require any code to see
the output. You can verify the result you see is only visible in the design section and not visible into the
device.
The main advantage is that it reflects instantly in the preview section so that you don’t want to run the build to check the result which saves a lot of development time.
Add the below tag into your XML file.
activity_main.xml
<LinearLayout xmlns:tools="http://schemas.android.com/tools">
<android.support.v7.widget.RecyclerView
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
tools:listitem="@layout/row_main"
/>
</LinearLayout>
> tools:listitem - attribute allows you to pass any layout file into the recycler-view to see the result.
row_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
tools:src="@tools:sample/avatars"
/>
<TextView
android:id="@+id/act_main_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginEnd="18dp"
android:onClick="@{(v)->click.onClick(v)}"
android:text="Hello World!"
android:textSize="16sp"
android:textStyle="bold|italic"
tools:text="@tools:sample/full_names"
/>
</LinearLayout>
Comments
Post a Comment