title: Android: Enable / Disable a button in Runtime?
body: <p>Ok, so I have two buttons. The first one is to "Load Text" and the second is to "Speak Out".</p>
  
  <p>Now, I don't want the Speak button to be active while there is no text loaded.</p>
  
  <p>I've managed to set value into the EditText by Load Text button's onClickListener method. Inside the same method I have called,</p>
  
  <pre><code>btnSpeak.setEnabled(true);
  </code></pre>
  
  <p>I have initialized this as,</p>
  
  <pre><code>btnSpeak = (Button) findViewById(R.id.button1);
  </code></pre>
  
  <p>The entire coding is,</p>
  
  <pre><code>@Override
  public void onInit(int status) {
  
      if (status == TextToSpeech.SUCCESS) {
  
          int result = tts.setLanguage(Locale.US);
  
          if (result == TextToSpeech.LANG_MISSING_DATA
          || result == TextToSpeech.LANG_NOT_SUPPORTED) {
              Log.e("TTS", "This Language is not supported");
          } else {
              btnSpeak.setEnabled(true);
              //for checking
              if(btnSpeak.isEnabled())
              {
                  Toast.makeText(SimpleAndroidOCRActivity.this, "Button should work!", Toast.LENGTH_SHORT).show();
              }
              else
              {
                  Toast.makeText(SimpleAndroidOCRActivity.this, "Button should not work!", Toast.LENGTH_SHORT).show();
              }
          }
  
      } else {
          Log.e("TTS", "Initilization Failed!");
      }
  
  }
  </code></pre>
  
  <p>This is to check the status and assign language to the TTS for further use. I get the toast as "Button should work" but it doesn't get enabled. Why is it so? What's the work around?</p>
  
  <p>I have in .xml file as,</p>
  
  <pre><code>&lt;Button
      android:id="@+id/button1"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:layout_width="200dp"
      android:enabled="false"
      android:text="@string/tts_text" /&gt;
  </code></pre>
  
  <p>Should I have it enabled in here and then disable and enable in runtime??</p>