Skip to main content

Posts

Showing posts from January, 2021

Lists and Grids in Android with RecyclerView Kotlin Tutorial

RecyclerView is a ViewGroup added to the android studio as a successor of the GridView and ListView. It has been created to make possible construction of any lists with XML layouts as an item that can be customized vastly while improving on the efficiency of ListViews and GridViews. Getting Started To implement a basic RecyclerView Two sub-parts are needed to be constructed which offer the users the degree of control they require in making varying designs of their choice. 1.The ViewHolder: The ViewHolder is a java class that stores the reference to the card layout views that have to be dynamically modified during the execution of the program by a list of data obtained either by online databases or added in some other way. 2.The Data Class: The Data class is a custom java class that acts as a structure for holding the information for every item of the RecyclerView. Implementation of the RecyclerView: In the activity_main.xml file in layout directory, add the RecyclerView widget. <?

Android Spinner using Kotlin

 In this example, we’ll be implementing Material Spinners in our Android Application using Kotlin. Android Spinner is used to create a drop-down list on the screen. What is Android Spinner? Spinners provide a quick way to select one value from a list. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one. You can add a spinner to your layout with the  Spinner  object. You should usually do so in your XML layout with a  <Spinner>  element. For example: <Spinner     android:id = "@+id/planets_spinner"     android:layout_width = "match_parent"     android:layout_height = "wrap_content" /> Spinner Callback Events  AdapterView.onItemSelectedListener interface is used to trigger the Spinner click event callbacks.  It consists of two methods:   1.onItemSelected   2.onNothingSelected XML Layout Code The code for the act