Skip to main content

Posts

Showing posts with the label RecyclerView

android kotlin - RecyclerView animation

MainActivity.kt package com.cfsuman.kotlintutorials import android.os.Bundle import android.widget.Button import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() { private lateinit var context:MainActivity override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Get the context context = this; // Get the widgets reference from XML layout val button = findViewById<Button>(R.id.button) val recyclerView = findViewById<RecyclerView>(R.id.recyclerView) // initialize a mutable list of animals val animals = mutableListOf( "Squirrel", "Mouse", "Chameleon", "Deer", "Raccoon", "Antelope", ...

android kotlin - RecyclerView smooth scroll

MainActivity.kt package com.cfsuman.kotlintutorials import android.os.Bundle import android.widget.Button import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() { private lateinit var context:MainActivity override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Get the context context = this; // Get the widgets reference from XML layout val btnTop = findViewById<Button>(R.id.btnTop) val btnMiddle = findViewById<Button>(R.id.btnMiddle) val btnBottom = findViewById<Button>(R.id.btnBottom) val recyclerView = findViewById<RecyclerView>(R.id.recyclerView) // initialize a mutable list of animals val animals = mutableListOf( "Horse...

Android Kotlin: How to create a horizontal RecyclerView

Creating a Horizontal Scrolling List with RecyclerView in Android (Kotlin) This code demonstrates how to create a horizontally scrolling list of items using RecyclerView in an Android application written in Kotlin. The code is divided into three parts: MainActivity.kt: This file defines the main activity of the application. It retrieves data (a list of animal names), sets up the RecyclerView with a horizontal layout manager, and binds the data to a custom adapter class. RecyclerViewAdapter.kt: This file defines the adapter class for the RecyclerView. It inflates a custom view for each item, binds the data to the view, and manages the number of items in the list. Layout XML files: These files define the layouts for the main activity ( activity_main.xml ) and the custom view for each item ( custom_view.xml ). Summary By combining these components, the code creates a RecyclerView that displays a list of animal names horizontally. Users can scroll through the list to see al...

Android Kotlin: RecyclerView divider line

Adding Divider Lines Between RecyclerView Items in Android (Kotlin) This code demonstrates how to display divider lines between items in a RecyclerView using Kotlin in an Android application. It achieves this by utilizing the DividerItemDecoration class provided by the Android framework. Components Breakdown: The code consists of three parts: MainActivity.kt: This file manages the overall activity lifecycle and configures the RecyclerView. RecyclerViewAdapter.kt: This file defines the adapter responsible for populating the RecyclerView with data and displaying individual items. activity_main.xml and custom_view.xml: These XML files define the layout structure for the activity and each item displayed in the RecyclerView. Summary The MainActivity.kt first initializes a list of animal names and sets up the RecyclerView with a LinearLayoutManager for vertical orientation. It then creates an adapter instance with the animal data and sets it on the RecyclerView. Finally, it cr...