728x90

단순히 String값이 비어있는지를 체크하고싶은 경우는 TextUtils을 이용하면 좋다.
TextUtils.isEmpty(string)
TextUtils.isEmpty() 를 클릭해서 메서드를 확인해보면 아래와 같다.
public static boolean isEmpty(@Nullable CharSequence str) {
    if (str == null || str.length() == 0)
        return true;
    else
        return false;
}

// 사용법
if(TextUtils.isEmpty(string)){
    // 정말 string 이 비어있으면 true 를 반환
    doSomething();
}


EditText et;
et = (EditText) findViewById(R.id.et01);
// EditText 내용을 가져오기
String getEdit = et.getText().toString();
if(TextUtils.isEmpty(getEdit)) {
    Toast.makeText(MainActivity.this, "값을 입력하세요." Toast.LENGTH_SHORT).show();
}




블로그 이미지

Link2Me

,