Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
How to Implement Circular ProgressBar in Android?
Next article icon

How to Implement Stepper Functionality in Android?

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A Stepper widget allows you to organize content in a sequence of steps, and the user can navigate between them. In this article we are going to implement a Stepper-like functionality in an Android app here we take the help of Tablayout to achieve this. A Sample video is attached below to get an idea about what we are going to do in this article.

Step By Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio and select the language as Kotlin.

Step 2: Change the StatusBar Color

Navigate to app > res > values > themes > themes.xml and add the below code under the style section in the themes.xml file.

<item name="android:statusBarColor" tools:targetApi="l">#308d46</item>

Step 3: Working with fragment_step.xml

Create a new Fragment resource file named it as fragment_step.xml it contains two text views for displaying the content of each step.

XML
<LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     android:padding="16dp">      <TextView         android:id="@+id/stepTitle"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textSize="24sp"         android:textStyle="bold"         android:layout_gravity="center_horizontal"         android:layout_marginBottom="16dp" />      <TextView         android:id="@+id/stepDescription"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textSize="16sp"         android:layout_gravity="center_horizontal" />    </LinearLayout> 

Step 4: Working with StepFragment.kt file

Create a new fragment kotlin file named it as StepFragment.kt . It contains two methods.

onCreateView Function:

  • It is responsible for inflating (loading) the fragment's layout XML file (fragment_step.xml) and returning the root View of that layout.
  • The layout defined in fragment_step.xml is inflated and added to the fragment's UI.

onViewCreated Function:

  • In this function, you can interact with the views defined in the fragment's layout.
  • Here, it's setting the text for two TextViews (stepTitle and stepDescription) with values passed in through the fragment's arguments (title and description).

StepFragment.kt:

Kotlin
package com.example.gfg  import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.fragment_step.*  // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private const val ARG_PARAM1 = "param1" private const val ARG_PARAM2 = "param2"  /**  * A simple [Fragment] subclass.  * Use the [StepFragment.newInstance] factory method to  * create an instance of this fragment.  */ class StepFragment(private val title: String, private val description: String) : Fragment() {     // TODO: Rename and change types of parameters     private var param1: String? = null     private var param2: String? = null      override fun onCreateView(         inflater: LayoutInflater, container: ViewGroup?,         savedInstanceState: Bundle?     ): View? {         // Inflate the layout for this fragment         return inflater.inflate(R.layout.fragment_step, container, false)     }      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {         super.onViewCreated(view, savedInstanceState)          // Set the title and description on the UI         stepTitle.text = title         stepDescription.text = description     }  } 

Step 5: Working with activity_main.xml

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. This xml file represents our app UI, our UI contains an Tablayout and an viewpager.

activity_main.xml:

XML
<LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     android:padding="16dp"     tools:context=".MainActivity">      <com.google.android.material.tabs.TabLayout         android:id="@+id/tabLayout"         android:layout_width="match_parent"         android:layout_height="wrap_content" />      <androidx.viewpager2.widget.ViewPager2         android:id="@+id/viewPager"         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="1" />  </LinearLayout> 

Step 6: Working with the MainActivity.kt file

Go to the MainActivity.kt and follow the below code. Below is the code for the MainActivity.kt. Comments are added inside the code to understand the code in more detail. In this class we are going to implement the fumtionality of the stepper in the application.

MainActivity.kt:

Kotlin
package com.example.gfg  import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.viewpager2.adapter.FragmentStateAdapter import com.google.android.material.tabs.TabLayoutMediator import kotlinx.android.synthetic.main.activity_main.*  class MainActivity : AppCompatActivity() {      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main)          // List of steps, where each step is represented by a StepFragment         val steps = listOf(             StepFragment("Step 1", "Description for Step 1"),   // Step 1             StepFragment("Step 2", "Description for Step 2"),   // Step 2             StepFragment("Step 3", "Description for Step 3")    // Step 3         )          // Create an adapter for the ViewPager2 that manages the steps         val adapter = object : FragmentStateAdapter(this) {             override fun getItemCount(): Int = steps.size             override fun createFragment(position: Int): Fragment = steps[position]         }          // Set the adapter for the ViewPager2         viewPager.adapter = adapter          // Attach the TabLayout to the ViewPager2 and set tab labels         TabLayoutMediator(tabLayout, viewPager) { tab, position ->               // Set tab labels like "Step 1," "Step 2," etc.             tab.text = "Step ${position + 1}"           }.attach()     } } 

Output:


Next Article
How to Implement Circular ProgressBar in Android?
author
chinmaya121221
Improve
Article Tags :
  • Kotlin
  • Android
  • Geeks Premier League
  • Geeks Premier League 2023

Similar Reads

  • How to Implement Custom Searchable Spinner in Android?
    Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it. The default value of the android spinner will be the c
    5 min read
  • How to Implement TextSwitcher in Android?
    In Android, TextSwitcher is a useful tool for displaying text with animations. It can be seen as a special version of ViewSwitcher, where its children are only TextView elements. TextSwitcher allows us to add smooth transitions to text, making it part of the transition widget family. Whenever you ca
    3 min read
  • How to Implement ViewPager with Dotsindicator in Android?
    ViewPager in Android is a class that allows the user to flip left and right through pages of data. This class provides the functionality to flip pages in-app. It is a widget found in the support library. What are Dotsindicator? These are dots that help us to see which view is currently opened when w
    4 min read
  • How to Implement Circular ProgressBar in Android?
    ProgressBar is used when we are fetching some data from another source and it takes time, so for the user's satisfaction, we generally display the progress of the task. In this article, we are going to learn how to implement the circular progress bar in an Android application using Java. So, this ar
    6 min read
  • How to Implement OTP View in Android?
    An OTP View or PinView in android is a widget that allows users to enter their PIN, OTP, etc. They are generally used for two-factor authentication or phone number verification by OTP. A sample video is given below to get an idea about what we are going to do in this article. Note: In order to imple
    2 min read
  • How to implement View Shaker in Android
    View Shaker is an animation in which, the UI of screen vibrates for a limited period of time. This can be implemented on the whole layout or some particular widget. It is a very common effect that developers use, especially to show incorrect credentials. View Shaker helps us to animate the widgets.
    3 min read
  • How to Implement Fab Explosion Animation in Android?
    When interacting with apps on our devices, animations add delight to the user's experience and create a sense of connection between the vibrant destinations. One of the animations on Android which enhances the user's experience is the FAB (Floating Action Button) Explosion Animation. Here, the user
    4 min read
  • How to Implement ClockAnimationView Library in Android?
    Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Further, it was developed for smartwatches and Android TV. Each of them has a specialized interface. Android has been one of the best-selling OS for smartphones. Android O
    2 min read
  • How to Implement Polling in Android?
    Many times you may have seen on some apps like youtube, LinkedIn, etc. polling is done and users choose their options whatever they want to choose. Here we are going to implement polling in Android Studio. What we are going to build in this article? In this article, we will ask the user a question a
    4 min read
  • How to Implement Shapeable ImageView in Android?
    In Android, ShapeableImageView is used to change the shape of your image to circle, diamond, etc. Also, you can set a corner radius to your ImageView. You can do much more by using this ShapeableImageView with minimal code. So in this article, we are going to make a ShapableImageView in android. By
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences