코틀린
[코틀린] 공부1
아스키의 공부방
2020. 12. 10. 23:45
728x90
반응형
findView..
Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btn : Button = findViewById(R.id.button)
val tv : TextView = findViewById(R.id.textView)
val etv : EditText = findViewById(R.id.editText)
etv.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
tv.text = etv.text
if (etv.text.length >= 6)
btn.visibility = View.VISIBLE
else
btn.visibility = View.INVISIBLE
}
override fun afterTextChanged(s: Editable?) {
}
})
btn.setOnClickListener {
Toast.makeText(this, tv.text, Toast.LENGTH_SHORT).show()
}
}
}
728x90
반응형