0

我的应用程序有Buttons,当你按下Buttons它们时,他们会使用文字转语音来说话。

我的Buttons工作很好,但是当我设置id.talk Button并给它语音命令时,它什么也没做。当我点击它时,什么也没有发生。

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;
    }
}
4

2 回答 2

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

btn.setOnClickListener(this);<---

您是否已将侦听器添加到新按钮?

于 2012-07-26T18:26:39.347 回答
0

请检查您是否使用 OnClickListener 注册了您的按钮

例如:

 mbutt = (Button) findViewById(R.id.talk);
   mbutt.setOnclickListener(this);
于 2012-07-26T18:33:23.853 回答