마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

getText.toStirng()이 안먹혀요

0 추천
<?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"
    android:orientation="vertical"
    tools:context=".addReview">


    <EditText
        android:id="@+id/user_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="패스워드"/>
    <EditText
        android:id="@+id/data"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="데이터 입력"/>
    <Button
        android:id="@+id/add_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="저장"/>
</LinearLayout>

레이아웃이 이렇게 되어 있고, 

EditText editText = findViewById(R.id.check_password);
check_password = editText.getText().toString();

이렇게 아이디 찾아줘서 getText.toStirng()을 하고

if(check_password!=null){
    Toast.makeText(CheckPassword.this, check_password ,Toast.LENGTH_SHORT).show();
    Log.d("tag","확인" + check_password);
}

이렇게 해줬는데 

보시다시피 토스트메시지에 아무것도안나옵니다

edittext는 저기 123적혀있는부분이고 log찍어봐도 확인이란 글자만나오구요

그러면 if문에 check_password != null이란게 동작을 하면안되는데 

또 저게 동작을 하네요? 데이터가 있는데, 데이터가 null인 마냥 출력하고, 그러고 if문은 또 먹히는 뭔가요?

익명사용자 님이 2019년 2월 27일 질문
해결됬습니다. 답변 안달아주셔도 되요

1개의 답변

0 추천
check_password != null && !check_password.equals("")

으로 한번 해보세요.
rhaps20 (6,010 포인트) 님이 2019년 2월 27일 답변
...