I need to do a two image button with onClick.That two image button have to be located in same place.one image button is to start functionality for voice record and other image button is stop functionality for voice record.
I done a functionality exactly.My only problem is to use two image button for stop and start in same place.
I searched many tutorials and SO posts.But I didn't get it.
Anyone can help me with this.
Just use one button and the method setBackgroundResource of the ImageButton. use one and the same button and in the onClick method use this line:
yourButton.setBackgroundResource(R.drawable.startImg); //for start of the recording
and
yourButton.setBackgroundResource(R.drawable.stopImg); //for stop of the recording
if (myAudioRecorder==null) {
myAudioRecorder.start();
audioButton.setImageResource(R.drawable.stop);
} else if (myAudioRecorder != null) {
audioButton.setImageResource(R.drawable.record);
}
Related
I need some help,
I have one ImageButton that plays and stops a tune, I want the button to change to a stop symbol when playing and then back to a play symbol when stopped. So far I have the symbol and tune playing when the ImageButton is clicked the first time, but when it is clicked the second time, the tune stops but the image does not change, any advice?
mPlayTune.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (tuneMp.isPlaying()) {
tuneMp.stop();
tuneMp.prepareAsync();
mPlayTune.setImageResource(R.drawable.ic_av_play_arrow);
}else
tuneMp.start();
mPlayTune.setImageResource(R.drawable.ic_av_stop);
}
});
Couldn't you just make 2 objects and hide or show them by clicking them? It's not a clean implementation but for sure a workaround.
I solved it, it was simply changing
tuneMp.start();
mPlayTune.setImageResource(R.drawable.ic_av_stop);
to
mPlayTune.setImageResource(R.drawable.ic_av_stop);
tuneMp.start();
this way it sets the icon before hitting tuneMp.start();
How do I make my Text-To-Speech stop speaking? Right now, my TTS will start speaking when I launch my application, but I'm trying to make it stop speaking when a button on my Main Activity is pressed.
I have tried creating an onStop() method and using .stop, but to no avail.
May I please get some help on this issue?
You could do something along the lines of this ...
stopSpeakingButton.setOnClickListener(new
View.OnClickListener() {
String toSpeak = " ";
textToSpeech.speak(
toSpeaks,TextToSpeech.QUEUE_FLUSH,null);
});
As you gave us no code this a concept , not the most beautiful solution but will work if you adjust for your use case, the idea is to make it read string with onny a space in it!
So building a new app specifically for the Android TV interface (lollipop leanback) and I'm using the PlaybackOverlayFragment that is provided by the framework which has a PlaybackControlsRow with all the usual controls on it.
The problem is, the default behavior is for the user to have to click the "Play" button to start the video and I want it to start automatically. That part is easy and I have it working but then the Play/Pause icons on the provided control are out of sync (showing play when should be pause) because the item was started outside of the events of clicking on that control.
Documentation is sparse on these framework elements and examining the class I can't find any public method that would allow me to put this control in the proper "mode" or tell it to display the play or pause icon myself.
Anyone with experience with these yet that would know how to do this?
In order to change the state of the button, even after adding your Actions to the Adapter, you'll need to notify the changes to the adapter that has your Action.
mPlayPauseAction.nextIndex(); // next index, if it was pause, it'll be play
notifyChanged(mPlayPauseAction);
// where notifyChanged(Action action) is:
private void notifyChanged(Action action) {
ArrayObjectAdapter adapter = mPrimaryActionsAdapter; // reference to your adapter
if (adapter.indexOf(action) >= 0) {
adapter.notifyArrayItemRangeChanged(adapter.indexOf(action), 1);
return;
}
}
Well, I partially answered my own question.
If I know before the PlaybackControlsRow is created that I want to set it to the pause state (actually, playing state but showing pause button) then if I call setIndex(PlaypauseAction.PAUSE) on the PlayPauseAction before adding it to the controlsrow then it works.
It doesn't appear that I can modify it myself after adding it but that may be something else I'm doing wrong.
i have an image with some text that i have the audio for.
I want to know how i can set it up so the user can the the button and the audio will start to play.
Thanks!
I have a solution I think it might work.
Fisrt of all, instead of working it an ImageView would be easier to work with ImageButton.
So, in your layour XML file, select ImageButton and create one using your image with the text.
also you might want to set a null bacground for your ImageButton, this is the code
android:background="#null"
Next, in your java class select the sound and the ImageButton and set it to play your sound when clicked.
would be like this
final MediaPlayer yourSoundName = MediaPlayer.create(Lotr1.this,R.raw.yoursoundfile);
final ImageButton yourImageButtonName =(ImageButton) findViewById(R.id.yourImage);
yourImageButtonName .setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
yourSoundName.start();
}
}
});
Any quenstion I would be glad to help
I have a simple sample for TransitionDrawable, when I click on ImageView one picture goes to second picture. But how on next click go back from second picture to one?
image.setImageDrawable(mTransition);
mTransition.startTransition(1000);
Just an idea,it may work for you.
take another transition animation xml file and reverse the images
take a vriable
int v=2;
and inside onClick,
public void onClick(){
if(v%2==0){
image.setImageDrawable(mTransition1);
mTransition1.startTransition(1000);
v++;
}
else{
image.setImageDrawable(mTransition2);
mTransition2.startTransition(1000);
v++;
}
}