2012-07-26 58 views
0

我的應用程序有Buttons當你按Buttons他們使用文字說話來說話。說話按鈕將不起作用

Buttons工作正常,但當我設置id.talkButton並給它的語音命令它什麼也沒做。當我點擊它時沒有任何反應。

public void onClick(View v) { 
    switch (v.getId()) { 

    // use switch case so each button does a different thing 
    // accurately(similar to an if statement) 
    case R.id.btn_speak: 
     String words1 = speakButton.getText().toString(); 

     // speakwords(xxxx); is the piece of code that actually calls the 
     // text to speech 
     speakWords(words1); 
     Intent voiceIntent = new Intent(
       "android.intent.action.RECOGNITIONMENU"); 
     startActivity(voiceIntent); 
     break; 
    case R.id.aboutbutton: 
     String words2 = infoButton.getText().toString(); 
     speakWords(words2); 
     Intent infoIntent = new Intent("android.intent.action.INFOSCREEN"); 
     startActivity(infoIntent); 
     break; 
    case R.id.voicebutton: 
     speakWords("Speak Now"); 
     startVoiceRecognitionActivity(); // call for voice recognition 
              // activity 
     break; 
    case R.id.talk: 
     speakWords("This is the main menu."); 
     break; 
    } 
} 
+0

請嘗試通過這個步進,看看什麼是真正回事。嘗試將'Log'輸出放入'case R.id.talk'中,並查看按下'Button'時是否顯示「Log」。讓我們知道結果。 – prolink007 2012-07-26 18:27:55

回答

1
btn =(Button) findViewById(R.id.talk); 
           ^^^^ 

btn.setOnClickListener(this);<--- 

有你添加監聽到你的新按鈕?

+0

神聖的CRAP我覺得很愚蠢。我必須在半小時內搞砸我的代碼,而我錯過了像聽衆那樣簡單的事情。 – 2012-07-26 18:34:08

0

請檢查有您註冊按鈕與OnClickListener

如:

mbutt = (Button) findViewById(R.id.talk); 
    mbutt.setOnclickListener(this);