package Ġcom . air sa id . mult ist ate layout . sample Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroid . widget . Button Ċ import Ġandroid . widget . TextView Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . air sa id . mult ist ate layout . sample . trigger . RecyclerView State Trigger Ċ import Ġcom . air sa id . mult ist ate layout . sample . trigger . Network State Trigger Ċ import Ġcom . cz . android . sample . api . Register Ċ import Ġcom . cz . android . sample . library . component . code . Sample Source Code Ċ import Ġkotlin . random . Random Ċ Ċ /** Ċ Ġ* Ġ@ author Ġair sa id Ċ Ġ*/ Ċ @ Register ( title Ġ= Ġ" State Trigger ", Ġpriority Ġ= Ġ 4 ) Ċ @ Sample Source Code Ċ class ĠMulti State Layout RecyclerView Fragment Ġ: ĠBase Multi State Layout Fragment () Ġ{ ĊĊĠ Ġprivate Ġval Ġm RecyclerView : ĠRecyclerView Ġby Ġlazy Ġ{ ĠfindViewById ( R . id . re cyclerView ) Ġ} ĊĊĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ ĊĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . fragment _ multi _ state _ layout _ recycler _ view , Ġcontainer , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Suppress Lint (" Notify DataSet Changed ") ĊĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĊĠĠĠ Ġval Ġmock Data Ġ= Ġget Mock Data () ĊĠĠĠ Ġval Ġsample Adapter Ġ= ĠSample Adapter ( mock Data ) ĊĠĠĠ Ġm Multi State Layout . add State Trigger ( RecyclerView State Trigger ( sample Adapter )) ĊĠĠĠ Ġm Multi State Layout . add State Trigger ( Network State Trigger ( require Context ())) ĊĊĠĠĠ Ġm RecyclerView . adapter Ġ= Ġsample Adapter ĊĊĠĠĠ ĠfindViewById < Button >( R . id . set Empty Data ). setOnClickListener Ġ{ ĊĠĠĠĠĠ Ġmock Data . clear () ĊĠĠĠĠĠ Ġsample Adapter . notify DataSet Changed () ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠfindViewById < Button >( R . id . set Full Data ). setOnClickListener Ġ{ ĊĠĠĠĠĠ Ġmock Data . clear () ĊĠĠĠĠĠ Ġmock Data . addAll ( getMock Data ()) ĊĠĠĠĠĠ Ġsample Adapter . notify DataSet Changed () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Mock Data (): ĠMutable List < String > Ġ{ ĊĠĠĠ Ġval Ġresult Ġ= Ġmutable ListOf < String >() ĊĠĠĠ Ġfor Ġ( i Ġin Ġ 0 .. Random . nextInt ( 1 0 , Ġ 1 0 0 )) Ġ{ ĊĠĠĠĠĠ Ġresult . add (" Item $ i ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġresult ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠSample Adapter ( private Ġval Ġdata : ĠMutable List < String >) Ġ: ĠRecyclerView . Adapter < Sample ViewHolder >() Ġ{ ĊĠĠĠ Ġoverride Ġfun ĠonCreate ViewHolder ( parent : ĠViewGroup , Ġview Type : ĠInt ) Ġ= ĠSample ViewHolder . newInstance ( parent ) ĊĊĠĠĠ Ġoverride Ġfun Ġon Bind ViewHolder ( holder : ĠSample ViewHolder , Ġposition : ĠInt ) Ġ{ ĊĠĠĠĠĠ Ġholder . text . text Ġ= Ġdata [ position ] ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠgetItem Count () Ġ= Ġdata . size ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠSample ViewHolder Ġprivate Ġconstructor ( item View : ĠView ) Ġ: ĠRecyclerView . ViewHolder ( item View ) Ġ{ ĊĠĠĠ Ġval Ġtext : ĠTextView Ġ= ĠitemView . findViewById ( android . R . id . text 1 ) ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠ Ġfun Ġnew Instance ( parent : ĠViewGroup ) Ġ= ĠSample ViewHolder ( ĊĠĠĠĠĠĠĠĠĠ ĠLayoutInflater . from ( parent . context ). inflate ( android . R . layout . simple _ list _ item _ 1 , Ġparent , Ġfalse )) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }