Source:
<code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.no_transition); try{ segIO.screenViewsTracking(ISegment.Values.LAUNCH_ACTIVITY); }catch(Exception e){ logger.error(e); } createAccountBtn = (RelativeLayout) findViewById(R.id.createAccount_button_layout); createAccountBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { createAccount(); } }); createAccountTv = (ETextView) findViewById(R.id.create_account_tv); requiredFieldsLayout = (LinearLayout) findViewById(R.id.required_fields_layout); optionalFieldsLayout = (LinearLayout) findViewById(R.id.optional_fields_layout); final ETextView optional_text=(ETextView)findViewById(R.id.optional_field_tv); optional_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { <START> if(optional_text.getText().toString().equalsIgnoreCase(getString(R.string.show_optional_text))) { <END> optionalFieldsLayout.setVisibility(v.VISIBLE); optional_text.setText(getString(R.string.hide_optional_text)); } else{ optionalFieldsLayout.setVisibility(v.GONE); optional_text.setText(getString(R.string.show_optional_text)); } } }); ImageButton closeButton = (ImageButton) findViewById(R.id.actionbar_close_btn); if(closeButton!=null){ closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } ETextView customTitle = (ETextView) findViewById(R.id.activity_title); if(customTitle!=null){ customTitle.setText(getString(R.string.register_title)); } ETextView eulaTv = (ETextView) findViewById(R.id.end_user_agreement_tv); eulaTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showEulaDialog(); } }); setupRegistrationForm(); hideSoftKeypad(); }</code><technical_language>Instead of comparing text, error prone, check visibility of optionalFieldsLayout</technical_language>

Target:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.no_transition); try{ segIO.screenViewsTracking(ISegment.Values.LAUNCH_ACTIVITY); }catch(Exception e){ logger.error(e); } eulaLink = findViewById(R.id.end_user_agreement_tv); createAccountBtn = (RelativeLayout) findViewById(R.id.createAccount_button_layout); createAccountBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { createAccount(); } }); createAccountTv = (ETextView) findViewById(R.id.create_account_tv); requiredFieldsLayout = (LinearLayout) findViewById(R.id.required_fields_layout); optionalFieldsLayout = (LinearLayout) findViewById(R.id.optional_fields_layout); final ETextView optional_text=(ETextView)findViewById(R.id.optional_field_tv); optional_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(optionalFieldsLayout.getVisibility() == View.VISIBLE) { optionalFieldsLayout.setVisibility(v.GONE); optional_text.setText(getString(R.string.show_optional_text)); } else{ optionalFieldsLayout.setVisibility(v.VISIBLE); optional_text.setText(getString(R.string.hide_optional_text)); } } }); ImageButton closeButton = (ImageButton) findViewById(R.id.actionbar_close_btn); if(closeButton!=null){ closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } ETextView customTitle = (ETextView) findViewById(R.id.activity_title); if(customTitle!=null){ customTitle.setText(getString(R.string.register_title)); } ETextView eulaTv = (ETextView) findViewById(R.id.end_user_agreement_tv); eulaTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showEulaDialog(); } }); setupRegistrationForm(); hideSoftKeypad(); }