ठीक है, तो मेरे पास दो बटन हैं। पहला "टेक्स्ट लोड करें" और दूसरा "स्पीक आउट" करना है।एंड्रॉइड: रनटाइम में एक बटन सक्षम/अक्षम करें?
अब, मैं नहीं चाहता कि बोलो बटन सक्रिय होने के लिए है, जबकि कोई पाठ भरी हुई है चाहता हूँ।
मैं लोड पाठ बटन के onClickListener विधि द्वारा EditText में मान सेट करने प्रबंधित किया है। एक ही विधि मैं कहा जाता है,
btnSpeak.setEnabled(true);
मैं के रूप में इस प्रारंभ कर दिया है,
btnSpeak = (Button) findViewById(R.id.button1);
पूरे कोडन है,
@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!");
}
}
इस स्थिति की जांच करने के लिए और भाषा आवंटित करने के लिए है अंदर आगे के उपयोग के लिए टीटीएस। मुझे टोस्ट मिलता है क्योंकि "बटन काम करना चाहिए" लेकिन यह सक्षम नहीं होता है। ऐसा क्यों है? आसपास क्या काम है?
मैं के रूप में .xml फ़ाइल में है,
<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" />
मैं इसे यहाँ और फिर में सक्षम अक्षम करें और क्रम में सक्षम होना चाहिए ??
जांच करें कि क्या आप सही आईडी – stinepike
साथ बटन प्रारंभ हाँ, मैं सही आईडी के साथ की है। – iMan