title: Android/Java and multiple "view states"
body: <p>Does anyone recognize this pattern and know of a tidy solution?</p>
  
  <p>I've got a view that can be in certain states. Let's call them <code>Neutral</code>, <code>Success</code>, <code>Error</code>, <code>InProgress</code>. In the view I've got multiple elements (Buttons, TextViews and a ProgressBar) that should either be visible/enabled depending on the state the view is in.</p>
  
  <p>Currently I've got methods that represent the states that do the necessary <code>.setEnabled()</code> and <code>.setVisibility()</code> calls. With 4 states and a couple of elements this becomes messy quite fast.</p>
  
  <p>I also feel that the <a href="http://en.wikipedia.org/wiki/State_pattern" rel="nofollow">State Pattern</a> is not necessarily a good solution but is something that personally springs to mind.</p>
  
  <p>I would love to hear what any of you think is a simple and tidy solution.</p>
  
  <p>Sample code:</p>
  
  <pre><code>void setIsRegistering() {
      isRegistering = true;
      isRegistered = false;
  
      progressBar.setVisibility(View.VISIBLE);
      successText.setVisibility(View.GONE);
      errorText.setVisibility(View.GONE);
  
      setupFooterButton.setEnabled(false);
      setupFooterButton.setText("Adding browser");
  }
  
  void setIsRegistered() {
      isRegistering = false;
      isRegistered = true;
  
      progressBar.setVisibility(View.INVISIBLE);
      successText.setVisibility(View.VISIBLE);
      errorText.setVisibility(View.GONE);
  
      setupFooterButton.setEnabled(true);
      setupFooterButton.setText("Next");
  }
  
  void setIsNotRegistered() {
      isRegistering = false;
      isRegistered = false;
  
      progressBar.setVisibility(View.INVISIBLE);
      successText.setVisibility(View.INVISIBLE);
      errorText.setVisibility(View.GONE);
  
      setupFooterButton.setEnabled(true);
      setupFooterButton.setText("Add browser");
  }`
  </code></pre>