EditText 에서 문자열을 가져오는 방법이다.
문자열을 가져올 때에는 EditText 를 getText() 로 데이터를 가져온 후 toString() 을 이용하여 문자열로 바꿔주면 된다.
EditText변수명.getText().toString()
코드로 실습해본 예시이다.
txtName = findViewById(R.id.txtName);
editName = findViewById(R.id.editName);
editPasswd = findViewById(R.id.editPasswd);
editEmail = findViewById(R.id.editEmail);
btnSave = findViewById(R.id.btnSave);
// 버튼 눌렀을 때
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 입력한 데이터를 문자열로 가져와서 변수에 담아준다.
String name = editName.getText().toString();
String password = editPasswd.getText().toString();
String email = editEmail.getText().toString();'Android' 카테고리의 다른 글
| Toast / SnackBar 메시지 처리 방법 (0) | 2023.01.26 |
|---|---|
| Log 처리 하는 방법 (0) | 2023.01.26 |
| EditText 사용법 (0) | 2023.01.26 |
| 오픈소스 라이브러리를 안드로이드 스튜디오에 적용하는 방법 (0) | 2023.01.26 |
| 화면의 UI 위젯들을 액티비티에서 가져다 사용하기 위한 방법 (0) | 2023.01.26 |