정보를 보호하는 대학생
<안드로이드 스터디 04> EditText 입력 후 버튼누르면 그대로 TextView 출력 본문
1. 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"
tools:context=".MainActivity"
android:orientation="vertical"
>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="버튼입니다"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
2. 코틀린 코드
package com.android.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.*
class MainActivity : AppCompatActivity() {
//////////변수선언/////////////////
lateinit var textView1: TextView
lateinit var button1 : Button
lateinit var editText1 : EditText
/////////////////////////////////
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView1 = findViewById(R.id.textView1)
button1 = findViewById(R.id.button1)
editText1 = findViewById(R.id.editText1)
button1.setOnClickListener{
textView1.text = editText1.text.toString()
}
}
}
3. 결과화면

'개발 > 안드로이드 스터디' 카테고리의 다른 글
<안드로이드 스터디 06> 색깔 등록, 기본 어플 색깔 설정 바꾸기 (0) | 2022.01.14 |
---|---|
<안드로이드 스터디 05> 체크박스 -> 라디오버튼 -> 버튼 -> 선택에 따른 이미지 보여주기 (0) | 2022.01.14 |
<안드로이드 스터디 03> 라디오 버튼을 누르면 토스트 띄우기 (0) | 2022.01.06 |
<안드로이드 스터디 02> 체크박스를 누르면 토스트 띄우기 (0) | 2022.01.06 |
<안드로이드 스터디 01> 간단한 계산기 만들기 (0) | 2022.01.06 |