Ok, so I have two buttons. The first one is to "Load Text" and the second is to "Speak Out".
Now, I don't want the Speak button to be active while there is no text loaded.
I've managed to set value into the EditText by Load Text button's onClickListener method. Inside the same method I have called,
btnSpeak.setEnabled(true);
I have initialized this as,
btnSpeak = (Button) findViewById(R.id.button1);
The entire coding is,
@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!");
}
}
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?
I have in .xml file as,
<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 have it enabled in here and then disable and enable in runtime??
setAlpha(. 5f); button. setClickable(false);
setClickable(false); Animation translateAnimation=new TranslateAnimation(0, 0, 0,150 ); translateAnimation.
A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the button clickable again.
@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())
{
btnSpeak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
YourVoicemethod();
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!");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With