Wraithious
Wraithious

Reputation: 395

setImageResource works intermittently

Sometimes setImageResource works, and sometimes it doesn't, why does this scenario work:

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

and this senerio does not work:

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

Why? everything in the last code I posted works EXCEPT for setImageResource, what is going wrong here????

So as per @Ankit Dubey 's sugestion I made a dedicated method to change the icon image of the mic button, and it did NOT make any difference:

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

It still only works sometimes, it doesn't make any sense!!

Upvotes: 0

Views: 140

Answers (0)

Related Questions