[안드로이드/Android/Kotlin/코틀린] 컨트롤러에 포커스 주는 법

SooYeon Yeon·2021년 11월 9일
0

안드로이드/Android

목록 보기
5/25
컨트롤러이름.requestFocus()

예를들어 아래와 같이 정의되어 있다고 하자.

val id = findViewById<EditText>(R.id.id_edit)
val pw = findViewById<EditText>(R.id.pw_edit)

id의 edittext가 공백일 경우에는 id로 포커스 (커서 이동)을, pw의 edittext가 공백일 경우에는 pw로 포커스 (커서 이동)을 하려면

if ("".equals(id.text.toString())) {
	id.requestFocus()
}
else if ("".equals(pw.text.toString())){
	pw.requestFocus()
}

위와 같이 작성하면 된다.

0개의 댓글