Posts

Showing posts with the label create button in android

Create a button and handle on click listener in Android Studio (Kotlin)

Image
How to create a button and handle OnClickListener in Kotlin using Android Studio?       DESCRIPTION       In this tutorial we will create a button and handle button click. We will display a Toast on the click of that button. However you can do your own functionality such as moving to some activity, opening fragment etc.       VIDEO             SOURCE CODE       Step 1:  Create a new Project  or  open new project Step 2: Code activity_main.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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" tools:context= ".MainActivity" > <Button ...

Create a button and handle on click listener in Android Studio

Image
Step 1: Create a new project or open your project How to create a new project? Step 2: activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <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:gravity= "center" tools:context= ".MainActivity" > <Button android:id= "@+id/button" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "Cick Button" /> </LinearLayout> Step2: MainActivity.java package com . blogspot . devofandroid . myapplication ; import android.support.v7.app.AppCompatActivity ; ...