Fetch Text From Editable TextField in Android Jetpack Compose Last Updated : 13 Mar, 2022 Comments Improve Suggest changes Like Article Like Report In Android, an EditText is a sub-class of TextView, a UI element used to take text input from the user. EditText is generally used to collect information from the user for storing details or giving inputs for performing a function. However, in Jetpack Compose, we have TextField to collect and display textual data. In this article, we will show you how you could implement an editable TextField and fetch the user input and display it in another TextField in Android using Jetpack Compose. Step by Step Implementation Step 1: Create a New Project in Android Studio To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project. Step 2: Working with the MainActivity.kt file Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail. Kotlin package com.geeksforgeeks.fetchedittext import android.os.Bundle import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.* import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { // Displaying the created elements MainContent() } } } // Creating a composable // function to display the Top Bar // MyContent() is set as content @Composable fun MainContent(){ Scaffold( topBar = {TopAppBar( title = {Text( "GFG | TextField Fetch Data", color = Color.White)}, backgroundColor = Color(0xff0f9d58)) }, content = { MyContent()} ) } // Creating a composable function MyContent() // to display editable TextField and a Button @Composable fun MyContent(){ // Getting local content val mContent = LocalContext.current // Creating a variable to store the // editable TextField value var mText by remember { mutableStateOf("") } // Creating an editable TextField, // storing the value in mText Column(Modifier.fillMaxWidth()) { TextField( value = mText, onValueChange = { mText = it }, label = { Text("Enter something...") }, modifier = Modifier .fillMaxWidth() .absolutePadding(10.dp, 100.dp, 10.dp, 0.dp) ) } // Creating a Button to display a Toast // consisting mText value upon click Box(Modifier.fillMaxSize(), Alignment.Center){ Button(onClick = { Toast.makeText(mContent, mText, Toast.LENGTH_LONG).show() }, colors = ButtonDefaults.buttonColors(backgroundColor = Color(0XFF0F9D58))) { Text(text = "Click", color = Color.White) } } } // Displaying preview // in Android Studio IDE @Preview(showBackground = true) @Composable fun DefaultPreview() { MainContent() } Output: In the following video, you can see that a Toast message displaying the editable TextField value is displayed when the Button is clicked. Comment More infoAdvertise with us Next Article Fetch Text From Editable TextField in Android Jetpack Compose aashaypawar Follow Improve Article Tags : Kotlin Android Android-Jetpack Similar Reads Architecture of 8085 microprocessor A microprocessor is fabricated on a single integrated circuit (IC) or chip that is used as a central processing unit (CPU).The 8085 microprocessor is an 8-bit microprocessor that was developed by Intel in the mid-1970s. It was widely used in the early days of personal computing and was a popular cho 11 min read Android Architecture Android architecture contains a different number of components to support any Android device's needs. Android software contains an open-source Linux Kernel having a collection of a number of C/C++ libraries which are exposed through application framework services. Among all the components Linux Kern 5 min read States of a Process in Operating Systems In an operating system, a process is a program that is being executed. During its execution, a process goes through different states. Understanding these states helps us see how the operating system manages processes, ensuring that the computer runs efficiently. Please refer Process in Operating Sys 11 min read Android Tutorial In this Android Tutorial, we cover both basic and advanced concepts. So whether you are a fresher (graduate) or an experienced candidate with several years of Android Development experience, you can follow this Android tutorial to kick-start your journey in Android app development. Our Android Tutor 15+ min read Activity Lifecycle in Android with Demo App In Android, an activity is referred to as one screen in an application. It is very similar to a single window of any desktop application. An Android app consists of one or more screens or activities. Each activity goes through various stages or a lifecycle and is managed by activity stacks. So when 9 min read Introduction to Android Development Android operating system is the largest installed base among various mobile platforms across the globe. Hundreds of millions of mobile devices are powered by Android in more than 190 countries of the world. It conquered around 71% of the global market share by the end of 2021, and this trend is grow 5 min read Android UI Layouts Layouts in Android define the user interface and hold UI controls or widgets that appear on the screen of an application. Every Android application consists of View and ViewGroup elements. Since an application contains multiple activitiesâeach representing a separate screenâevery activity has multip 5 min read Top 50 Android Interview Questions and Answers - SDE I to SDE III A Linux-based open-source OS, Android was created by Andy Rubin and became one of the most popular smartphone operating systems. With 71 percent of the market share worldwide, Android is on top. Because it is on top in the smartphone OS, Android development is always in demand.If you are seeking a j 15+ min read Components of an Android Application There are some necessary building blocks that an Android application consists of. These loosely coupled components are bound by the application manifest file which contains the description of each component and how they interact. The manifest file also contains the appâs metadata, its hardware confi 3 min read Kotlin Tutorial This Kotlin tutorial is designed for beginners as well as professional, which covers basic and advanced concepts of Kotlin programming language. In this Kotlin tutorial, you'll learn various important Kotlin topics, including data types, control flow, functions, object-oriented programming, collecti 4 min read Like