So, I have two buttons. The first is “Download Text,” and the second is “Speak.”
Now I do not want the Speak button to be active until the text is loaded.
I managed to set the value in EditText with the Load Text onClickListener button. Inside the same method, I called
btnSpeak.setEnabled(true);
I initialized it as,
btnSpeak = (Button) findViewById(R.id.button1);
All encoding
@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);
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!");
}
}
This is a status check and language assignment for TTS for future reference. I get a toast like “Button should work,” but it doesn't activate. Why is this so? What job?
I have a .xml file like,
<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" />
Should I enable it here and then disable and enable it at runtime?
source
share