我的应用已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;
}
}
答案 0 :(得分:1)
btn =(Button) findViewById(R.id.talk);
^^^^
btn.setOnClickListener(this);<---
您是否为新按钮添加了监听器?
答案 1 :(得分:0)
请检查您是否使用OnClickListener
注册了按钮<强>例如强>
mbutt = (Button) findViewById(R.id.talk);
mbutt.setOnclickListener(this);