package Ġcom . by d . first code . kotlin . four . recycler Ċ Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . St agger ed Grid LayoutManager Ċ import Ġcom . by d . first code . kotlin . R Ċ import Ġcom . by d . first code . kotlin . four . F ruit Ċ import Ġkotlinx . android . synt hetic . main . activity _ recycler .* Ċ import Ġjava . lang . StringBuilder Ċ Ċ class ĠRe cycler Activity Ġ: ĠAppCompatActivity () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġfruit List = ArrayList < F ruit >() ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ recycler ) ĊĠĠĠĠĠĠĠ Ġinit F ru its () Ċ // ĠĠĠĠĠĠĠ Ġval Ġlayout Manager Ġ= ĠLinearLayoutManager ( this ) ĊĠĠĠĠĠĠĠ Ġval Ġlayout Manager Ġ= ĠSt agger ed Grid LayoutManager ( 3 , St agger ed Grid LayoutManager . VERTICAL ) Ċ // ĠĠĠĠĠĠĠ Ġlayout Manager . orientation = Linear LayoutManager . HORIZONTAL ĊĠĠĠĠĠĠĠ Ġre cyclerView . layout Manager = layout Manager ĊĠĠĠĠĠĠĠ Ġval Ġadapter Ġ= ĠF ruit Adapter ( fruit List ) ĊĠĠĠĠĠĠĠ Ġre cyclerView . adapter = adapter ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinit F ru its (){ ĊĠĠĠĠĠĠĠ Ġrepeat ( 2 ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfruit List . add ( F ruit ( getRandom Length (" che "), R . drawable . ic _ launcher _ background )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfruit List . add ( F ruit ( getRandom Length (" b aba "), R . drawable . switch 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfruit List . add ( F ruit ( getRandom Length (" water "), R . drawable . ic _ launcher _ background )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠgetRandom Length ( str : String ): String { ĊĠĠĠĠĠĠĠ Ġval Ġn Ġ= Ġ( 1 .. 2 0 ). random () ĊĠĠĠĠĠĠĠ Ġval Ġbuild Ġ= ĠStringBuilder () ĊĠĠĠĠĠĠĠ ĠLog . d (" test ", n . toString ()); ĊĠĠĠĠĠĠĠ Ġrepeat ( n ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbuild . append ( str ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġcontent Ġ= Ġbuild . toString () ĊĠĠĠĠĠĠĠ ĠLog . d (" test 1 ", content ); ĊĠĠĠĠĠĠĠ Ġreturn Ġcontent ĊĠĠĠ Ġ} Ċ Ċ }