package Ġcom . example . recyclerview demo Ċ Ċ import Ġandroid . support . v 7 . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . support . v 7 . widget . RecyclerView Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . Toast Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity (), ĠView . OnClickListener Ġ{ ĊĊĠĠĠ Ġval Ġcountries Ġ= ĠarrayOf < String >( ĊĠĠĠĠĠĠĠ Ġ" Af gh an istan "," Al ban ia "," Al ger ia "," And or ra "," Ang ola ", ĊĠĠĠĠĠĠĠ Ġ" An gu illa "," Ant ig ua Ġ& ĠBar bu da "," Arg ent ina "," Ar men ia "," Ar uba "," A ustralia "," A ust ria ", ĊĠĠĠĠĠĠĠ Ġ" A zer ba ij an "," B ah am as "," B ah rain "," Bang l ade sh "," Bar bad os "," Bel ar us "," Bel g ium "," Bel ize ", ĊĠĠĠĠĠĠĠ Ġ" Ben in "," B erm uda "," Bh ut an "," B ol iv ia "," B os nia Ġ& amp ; ĠHer ze gov ina "," Bot sw ana "," Br azil ", ĊĠĠĠĠĠĠĠ Ġ" B rit ish ĠV irgin ĠIslands "," B run ei "," Bul g aria "," Bur k ina ĠF aso "," Bur und i "," Camb od ia "," Cam ero on ", ĊĠĠĠĠĠĠĠ Ġ" C ape ĠVer de "," C ay man ĠIslands "," Ch ad "," Ch ile "," China "," Colo mb ia "," Con go "," Cook ĠIslands ", ĊĠĠĠĠĠĠĠ Ġ" Cost a ĠR ica "," C ote ĠD ĠI vo ire "," C ro at ia "," C ru ise ĠShip "," Cub a "," Cy pr us "," C zech ĠRepublic ", ĊĠĠĠĠĠĠĠ Ġ" Den mark "," Dj ib out i "," Dom in ica "," Dom in ican ĠRepublic ", Ġ" E cu ador "," E gy pt "," El ĠSal v ador ", ĊĠĠĠĠĠĠĠ Ġ" Equ ator ial ĠGu ine a "," Est onia "," Eth iop ia "," F alk land ĠIslands "," Far oe ĠIslands "," Fi ji "," Fin land ", ĊĠĠĠĠĠĠĠ Ġ" Fr ance "," F rench ĠPol yn es ia "," F rench ĠWest ĠInd ies "," G ab on "," G amb ia "," Ge org ia "," Ger many ", ĊĠĠĠĠĠĠĠ Ġ" Gh ana "," G ibr alt ar "," G ree ce "," Green land ", Ġ" G ren ada "," Gu am "," Gu ate mal a "," Gu ern sey "," Gu ine a ", ĊĠĠĠĠĠĠĠ Ġ" Gu ine a ĠB issa u "," Gu y ana "," H ait i "," H ond uras "," H ong ĠK ong "," H ung ary "," I cel and ", ĊĠĠĠĠĠĠĠ Ġ" In dia "," Ind onesia "," I ran "," I ra q "," I rel and "," Is le Ġof ĠMan "," Is ra el "," It aly "," J ama ica ", ĊĠĠĠĠĠĠĠ Ġ" J apan "," J ersey "," J ordan "," K az ak h stan ", Ġ" K en ya "," Ku wait "," Ky rg yz ĠRepublic "," La os "," Lat via ", ĊĠĠĠĠĠĠĠ Ġ" L eb anon "," Les oth o "," Li ber ia "," Lib ya "," L ie chten stein "," L ith uan ia "," L ux emb our g "," Mac au ", ĊĠĠĠĠĠĠĠ Ġ" Mac ed onia "," Mad ag as car "," Mal aw i "," Mal ays ia "," Mal div es "," M ali "," Mal ta "," M aur it ania ", ĊĠĠĠĠĠĠĠ Ġ" M aur it ius "," M ex ico "," Mol do va "," Mon aco ", Ġ" Mong ol ia "," Mont ene gro "," Mont serrat "," Mor oc co ", ĊĠĠĠĠĠĠĠ Ġ" Mo z amb ique "," Nam ib ia "," N ep al "," Ne therlands "," Ne therlands ĠAnt il les "," New ĠC aled onia ", ĊĠĠĠĠĠĠĠ Ġ" New ĠZe al and "," N ic ar ag ua "," N iger "," N iger ia "," Nor way "," O man "," P ak istan "," P ale st ine ", ĊĠĠĠĠĠĠĠ Ġ" Pan ama "," P ap ua ĠNew ĠGu ine a "," Par ag u ay "," Per u "," Phil ipp ines "," Pol and "," Port ugal ", ĊĠĠĠĠĠĠĠ Ġ" P uer to ĠR ico "," Q atar "," Re union "," Rom ania "," R uss ia "," Rw anda "," S aint ĠP ier re Ġ& ĠM ique lon ", ĊĠĠĠĠĠĠĠ Ġ" Sam oa "," San ĠMar ino "," S atellite "," S aud i ĠAr ab ia "," S ene gal "," Ser b ia "," Se y che l les "," Si erra ĠLe one ", ĊĠĠĠĠĠĠĠ Ġ" Sing apore "," S lov ak ia "," S lo ven ia "," South ĠA frica ", Ġ" South ĠK orea "," Sp ain "," S ri ĠL ank a ", ĊĠĠĠĠĠĠĠ Ġ" St ĠKit ts Ġ& ĠNe vis ", Ġ" St ĠLuc ia "," St ĠV in cent "," St . ĠLuc ia "," S ud an "," Sur iname "," Sw azil and ", ĊĠĠĠĠĠĠĠ Ġ" Sw eden ", Ġ" Sw it zer land "," Sy ria "," T aiwan "," T aj ik istan "," T anz ania "," Th ail and "," Tim or ĠL ' Este ", ĊĠĠĠĠĠĠĠ Ġ" To go "," T ong a "," Tr in idad Ġ& amp ; ĠT ob ago "," T un is ia "," Tur key ", Ġ" Tur k men istan "," Tur ks Ġ& ĠCa icos ", ĊĠĠĠĠĠĠĠ Ġ" Ug anda "," Uk ra ine "," United ĠAr ab ĠEm ir ates "," United ĠKing dom "," Ur ugu ay "," Uz be k istan "," V ene z ue la ", ĊĠĠĠĠĠĠĠ Ġ" V iet nam "," V irgin ĠIslands Ġ( US ) "," Y em en "," Z amb ia "," Z im bab we ") ĊĊĠĠĠ Ġval Ġadapter Ġ= ĠCountry Adapter ( countries , Ġthis ) ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĊĠĠĠĠĠĠĠ Ġval Ġre cyclerView Ġ= ĠfindViewById < View >( R . id . recyclerview Id ) Ġas ĠRecyclerView ĊĠĠĠĠĠĠĠ Ġre cyclerView . layout Manager Ġ= ĠLinearLayoutManager ( this ) ĊĠĠĠĠĠĠĠ Ġre cyclerView . adapter Ġ= Ġadapter ĊĊĠĠĠĠĠĠĠ ĠfindViewById < View >( R . id . button _ update _ country ). setOnClickListener Ġ{ update Letter Country ()} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonClick ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġindex Ġ= Ġview . tag Ġas ĠInt ĊĠĠĠĠĠĠĠ Ġval Ġcountry Ġ= Ġcountries [ index ] ĊĊĠĠĠĠĠĠĠ ĠToast . makeText ( this , Ġ" The Ġcountry Ġselected Ġ: Ġ${ country }", ĠToast . LENGTH _ SHORT ). show () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġupdate Letter Country (){ ĊĠĠĠĠĠĠĠ Ġval Ġlast Letter Ġ= Ġcountries [ 0 ]. last () ĊĊĠĠĠĠĠĠĠ Ġfor (( index , country ) Ġin Ġcountries . with Index ()){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif ( last Letter . is UpperCase ()){ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcountries [ index ]= country . toLowerCase (). capitalize () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} else { ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcountries [ index ]= country . toUpperCase (). capitalize () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġadapter . notify DataSet Changed () ĊĠĠĠ Ġ} Ċ } Ċ