0

Hi please help to assist me on this.

So I created a res xml file under folder res/values (fm_login.xml) and the content as follow:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="fm_screen_name"></string>
    <string name="fm_email_address"></string>
</resources>

The main purpose is to check this file and make it as a setting page for the app. So later my code is looks like this for main activity

    // Welcome message
    String fm_email_address = getResources().getString(R.string.fm_email_address);

    if (fm_email_address == "") {
        strEmail_Exist = false;
        Toast.makeText(getApplicationContext(), "Please sign up", Toast.LENGTH_SHORT).show();

        // View SignUp Button

    } else {
        strEmail_Exist = true;
        String strScreen_Name = getResources().getString(R.string.fm_screen_name);
        Toast.makeText(getApplicationContext(), "Welcome, " + strScreen_Name, Toast.LENGTH_SHORT).show();

        // View Menu Button
    }

Question, when I emptied the value why I can't check if it's empty? Or should I use null to compare. Because for the first time user I need to make use their name/email is not registered yet in the app/mobile.

Appreciate for the assistance, since it's been pending for a while.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
seageath
  • 17
  • 5

1 Answers1

0

First get your String Resource value in A String variable than use TextUtils.isEmpty to check it is empty or not

String fm_email_address = getResources().getString(R.string.fm_email_address);
if (TextUtils.isEmpty(fm_email_address)) {
        //do something Your String is empty
}else{
        //do something Your String is not empty
}
Goku
  • 9,102
  • 8
  • 50
  • 81