quilt code

[kotlin] 버튼 클릭 이벤트 (1) 본문

daily/Android

[kotlin] 버튼 클릭 이벤트 (1)

김뱅쇼 2023. 5. 26. 15:39

**emulator에 출력할 때 

  manifests에서 android name을 제대로 설정해야함!!

 

 

 


클릭하면 good Morning이 good evening이 되도록



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package kr.co.aiai.app
 
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
// : 상속
class MainActivity : AppCompatActivity() {
    //메소드
    //fun : 파이썬의 def
    override fun onCreate(savedInstanceState: Bundle?) {
        //super:자기 조상 호출
        super.onCreate(savedInstanceState)
        //화면으로 넘어가는 명령어
        setContentView(R.layout.activity_main)
        //버튼을 클릭하면 good evening으로 넘어가게
        val tv = findViewById<TextView>(R.id.tv)
 
        var btn:Button = findViewById(R.id.btn)
 
        btn.setOnClickListener {
            tv.setText("Good Evening")
        }
 
 
   }
}
cs




클릭








'daily > Android' 카테고리의 다른 글

[kotlin] 버튼 클릭 이벤트 (2)  (0) 2023.05.26
[kotlin] 로또 번호 생성  (0) 2023.05.26