โ ์ค๋ ๋ฐฐ์ธ ๋ด์ฉ
- EditText ์ ์ ๋ ฅ๋ ํ ์คํธ ๊ฐ์ ธ์ค๊ธฐ
- ๋น๋ฐ๋ฒํธ ์ฒดํฌํ๋ ์กฐ๊ฑด๋ฌธ ๋ง๋ค๊ธฐ
โ EditText์ ์ ๋ ฅ๋ ํ ์คํธ ๊ฐ์ ธ์ค๊ธฐ
๐ ์ฃผ์ ๐
Edit Text ์ปดํฌ๋ํธ์ text๋ฅผ ๋ถ๋ฌ์ฌ ๋๋
๋ค์ ๊ผญ .toString()์ ๋ถ์ฌ์ผ ํจ!
// EditText ์ปดํฌ๋ํธ๋ฅผ ์ฐพ์์ editText ๋ณ์์ ์ ์ฅํ๋ค.
val editText = findViewById<EditText>(R.id.์์ด๋)
// editText ์์ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ํ
์คํธ๋ฅผ ๋ถ๋ฌ์ passwordText ์ ์ ์ฅํ๋ค.
val passwordText = editText.text.toString()
EditText๋?
์ผ๋ฐ TextView โ ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ์ ์๋ ์ปดํฌ๋ํธ โญ
text ์์ฑ์ด ์ผ๋ฐ textView์ ๋ฌ๋ฆฌ EditText ๋ง์ ํํ๋ก ์ค์ ๋จ.
๋ฐ๋ผ์ ๊ทธ ์์ ์ ๋ ฅ๋ ํ ์คํธ๋ฅผ ๊ฐ์ ธ์ค๋ ค๋ฉด toString() ์ ๋ถ์ฌ์ผ ํจ!!
โ ๋น๋ฐ๋ฒํธ ์ฒดํฌํ๋ ์กฐ๊ฑด๋ฌธ ๋ง๋ค๊ธฐ
์กฐ๊ฑด๋ฌธ์ ์ด์ฉํด ์ฐ๋ฆฌ๊ฐ ์ํ๋ ํ ์คํธ(๋น๋ฐ๋ฒํธ)๊ฐ ๋ง๋์ง ์ฒดํฌํ๊ธฐ!
๐ == ์ฐ์ฐ์?
์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ์ด ๊ฐ์์ง ๋น๊ตํ๋ ์ฐ์ฐ์
=> if (์กฐ๊ฑด๋ฌธ) ์์ ์กฐ๊ฑด๋ฌธ์ ๊ฒฐ๊ณผ๊ฐ ์ฐธ์ธ์ง ๊ฑฐ์ง์ธ์ง ํ๋จํ์ฌ ์กฐ๊ฑด๋ฌธ ์คํ
if ( passwordText == "12345678" )
// ์ฐธ์ด๋ผ๋ฉด(์
๋ ฅํ passwordText ์ "12345678"์ด ๊ฐ๋ค๋ฉด) ์ด๊ณณ์ ๋ช
๋ น ์คํ
} else {
// ๊ฑฐ์ง์ด๋ผ๋ฉด(๋ค๋ฅด๋ค๋ฉด) ์ด๊ณณ์ ๋ช
๋ น ์คํ
}
โ ์ค๋์ ๋ฌธ์ : ๋น๋ฐ๋ฒํธ ์ฒดํฌํ๊ธฐ
โก ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๋น๋ฐ๋ฒํธ๋ฅผ passwordText ๋ณ์์ ์ ์ฅ
โก passwordText ๋ฅผ ์ฒดํฌํ์ฌ ์ํ๋ ๋น๋ฐ๋ฒํธ๊ฐ ๋ง์ ๊ฒฝ์ฐ
Logcat์ “ํต๊ณผ”๋ฅผ ์ถ๋ ฅํ๊ณ , ์๋ ๊ฒฝ์ฐ “ํ๋ ธ์ด์.“๋ฅผ ์ถ๋ ฅ
โ [์ ํ] ์ค๋์ ์ฌํ ๋ฌธ์ : ์์ด๋(์ด๋ฉ์ผ), ๋น๋ฐ๋ฒํธ ์ฒดํฌํ๊ธฐ
โก ์ด๋ฉ์ผ ์ ๋ ฅ ์ฐฝ ์ถ๊ฐ
โก ์ด๋ฉ์ผ์ด ํ๋ ธ์ ๊ฒฝ์ฐ “์ด๋ฉ์ผ์ด ํ๋ ธ์ด์” ์ถ๋ ฅ
- ์ด๋ฉ์ผ์ด ๋ง์ง๋ง ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ ๋๋ “๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ด์.” ์ถ๋ ฅ
- ์ด๋ฉ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๊ฐ ๋ง์ ๊ฒฝ์ฐ “ํต๊ณผ” ์ถ๋ ฅ
๐ xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="40dp"
android:text="์์ด๋์ ๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
app:layout_constraintHorizontal_bias="0.024"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="88dp"
android:text="์ด๋ฉ์ผ"
app:layout_constraintHorizontal_bias="0.013"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="180dp"
android:text="๋น๋ฐ๋ฒํธ"
app:layout_constraintHorizontal_bias="0.013"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextEmail"
android:layout_width="0dp"
android:layout_height="44dp"
android:layout_marginStart="10dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="10dp"
android:ems="10"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<EditText
android:id="@+id/editTextNumberPassword2"
android:layout_width="0dp"
android:layout_height="44dp"
android:layout_marginStart="10dp"
android:layout_marginTop="140dp"
android:layout_marginEnd="10dp"
android:ems="10"
android:inputType="numberPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="21dp"
android:layout_marginEnd="10dp"
android:text="ํ์ธ"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextNumberPassword2" />
</androidx.constraintlayout.widget.ConstraintLayout>
๐ kt
package com.comu.android.secretmemo
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<Button>(R.id.button).setOnClickListener{
// EditText ์ปดํฌ๋ํธ๋ฅผ ์ฐพ์์ editText ๋ณ์์ ์ ์ฅํ๋ค.
val editEmail = findViewById<EditText>(R.id.editTextEmail)
val emailText = editEmail.text.toString()
// editText ์์ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ํ
์คํธ๋ฅผ ๋ถ๋ฌ์ passwordText ์ ์ ์ฅํ๋ค.
val editText=findViewById<EditText>(R.id.editTextNumberPassword2)
val pwText=editText.text.toString()
if(emailText == "guswlsdl04@naver.com"){
if(pwText == "123456"){
Log.d("SecretMemo", "ํต๊ณผ")
}
else{
Log.d("SecretMemo","๋น๋ฐ๋ฒํธ ์ค๋ฅ")
}
}
else Log.d("SecretMemo", "์ด๋ฉ์ผ ์ค๋ฅ")
}
}
}
๐ ์คํ๊ฒฐ๊ณผ 1
๐ ์คํ๊ฒฐ๊ณผ 2
https://codemate.kr/@guswlsdl04/๋ชจ๊ฐ์ฝ-์ฝํ๋ฆฐ-๊ธฐ์ดํธ-11์ผ์ฐจ โ CLICK HERE!
'๐ป Extracurricular > ์ฝ๋ฎค๋ํฐ ๋ชจ๊ฐ์ฝ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ชจ๊ฐ์ฝ < Kotlin ๊ธฐ์ดํธ > - 13์ผ์ฐจ (0) | 2022.03.14 |
---|---|
๋ชจ๊ฐ์ฝ < Kotlin ๊ธฐ์ดํธ > - 12์ผ์ฐจ (0) | 2022.03.14 |
๋ชจ๊ฐ์ฝ < Kotlin ๊ธฐ์ดํธ > - 10์ผ์ฐจ (0) | 2022.03.09 |
๋ชจ๊ฐ์ฝ < Kotlin ๊ธฐ์ดํธ > - 9์ผ์ฐจ (0) | 2022.03.09 |
๋ชจ๊ฐ์ฝ < Kotlin ๊ธฐ์ดํธ > - 8์ผ์ฐจ (0) | 2022.03.09 |