有时setImageResource有效,有时候它没有,为什么这个场景有效:
edit4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mySpeech = edit3.getText().toString();
if(!mySpeech.equals("")){
edit1.setImageResource(R.drawable.mic_icon2);
speakIT(mySpeech);
}
}
});
}
public void SpeechTimer(){//used for determining when computer is done speaking
int a=0;
while(tts.isSpeaking()){
a+=1;
if(a>10){
a=0;
}
}
edit1.setImageResource(R.drawable.mic_icon);
}
这个senerio不起作用:
if(!holdForGMS.equals("add my voice")&& !holdForGMS.contains("my name is")&& !holdForGMS.contains("delete voice print")&& !holdForGMS.equals("what is my name")&& set==0) {
set=1;
edit1.setImageResource(R.drawable.mic_icon3);
speakIT(holdForGMS);
}
为什么呢?我发布的最后一个代码中的所有内容都为setImageResource设置了EXCEPT,这里出了什么问题????
因此,根据@Ankit Dubey的消息,我制作了一个专门的方法来改变麦克风按钮的图标图像,它没有任何区别:
public void Icons(int which, String words){
if(which==1){
edit1.setImageResource(R.drawable.mic_icon);
if(!words.equals("")){
speakIT(words);
}
}
if(which==2){
edit1.setImageResource(R.drawable.mic_icon2);
if(!words.equals("")){
speakIT(words);
}
}
if(which==3){
edit1.setImageResource(R.drawable.mic_icon3);
if(!words.equals("")){
speakIT(words);
}
}
}
它有时仍然有效,它没有任何意义!!