Skip to content

QueenieCplusplus/Android_Review_1_plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android_Review_1_plus

Toast & extract res/val/string & default import hotkey

layout see:

      <?xml version="1.0" encoding="utf-8"?>

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         xmlns:tools="http://schemas.android.com/tools"
         android:orientation="vertical"
         android:layout_gravity="center_vertical"
         tools:context=".MainActivity">

         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
             android:textSize="30sp"
             android:text="@string/txt1" />

         <Button
             android:id="@+id/btn"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
             android:text="@string/btn1" />


     </LinearLayout>

code see:

     package com.example.kateskotlinandroid2021

     import androidx.appcompat.app.AppCompatActivity
     import android.os.Bundle
     import android.widget.Button
     import android.widget.Toast

     class MainActivity : AppCompatActivity() {

         override fun onCreate(savedInstanceState: Bundle?) {

             super.onCreate(savedInstanceState)
             setContentView(R.layout.activity_main)
             // inside onCreate() and after setContentView
             val KButton: Button = findViewById(R.id.btn)
             KButton.setOnClickListener{ afterClick()}

         }

         private fun afterClick() {
             Toast.makeText(this, "Welcome to 2021, Dear Kate!",
                 Toast.LENGTH_SHORT).show()
         }
     }