Activity: A single user-based task, usually, but not always, containing views
Layout, View & View Group: Visual arrangement of views and view groups, UI
Content Provider: A component that serves data to other application
Broadcast receiver: Component receiving notifications from other activities
Service: Background process responding local or remote application requests
Context: Object containing the global state of an application environment
Intent: A messaging object to request an action from another app component -> component들 (Activity, Service, Content Provider, Broadcast receiver) 간의 통신을 맡음
<?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:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView2"
android:orientation="horizontal"
android:layout_width="300dp"
android:layout_height="300dp"
app:srcCompat="@drawable/chicken" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
package com.example.eduskkumapweek3
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//여기에
var counter = 0
val textview = findViewById<TextView>(R.id.textView)
val imageview = findViewById<ImageView>(R.id.imageView2)
val leftbtn = findViewById<Button>(R.id.button5)
val rightbtn = findViewById<Button>(R.id.button6)
//textview.text = "pizza"
imageview.setImageResource(R.drawable.pizza)
rightbtn.setOnClickListener{
if (counter == 0){
textview.text = "chicken"
imageview.setImageResource(R.drawable.chicken)
counter++
}
else if (counter == 1){
textview.text = "hamburger"
imageview.setImageResource(R.drawable.hamburger)
counter++
}
else if (counter == 2){
textview.text = "ramen"
imageview.setImageResource(R.drawable.ramen)
counter++
}
else {
//Toast.makeText(context: this@MainActivity, text: "Last Menu", Toast.LENGTH_LONG).show()
Toast.makeText(this@MainActivity, "Last Menu", Toast.LENGTH_LONG).show()
}
}
leftbtn.setOnClickListener{
if (counter == 3){
textview.text = "hamburger"
imageview.setImageResource(R.drawable.hamburger)
counter--
}
else if (counter == 2){
textview.text = "chicken"
imageview.setImageResource(R.drawable.chicken)
counter--
}
else if (counter == 1){
textview.text = "pizza"
imageview.setImageResource(R.drawable.pizza)
counter--
}
else{
Toast.makeText(this@MainActivity, "First Menu", Toast.LENGTH_LONG).show()
}
}
}
}