I am attempting to use some of Google’s code from their audio capture sample code. They simplified the heck out of their code and made their layout within the class. I want to have an actual xml layout. I know how to do that part, but I would like to know how to change the code below to an onClick method and have all the functionality that is provided with it.
class PlayButton extends Button {
boolean mStartPlaying = true;
OnClickListener clicker = new OnClickListener() {
public void onClick(View v) {
onPlay(mStartPlaying);
if (mStartPlaying) {
setText("Stop playing");
} else {
setText("Start playing");
}
mStartPlaying = !mStartPlaying;
}
};
public PlayButton(Context ctx) {
super(ctx);
setText("Start playing");
setOnClickListener(clicker);
}
}
Any help is appreciated.
In the layout file, you’ll have something like…
In the activity, onCreate(), you can then do something like..
ALTERNATELY, you can also define the method in the xml layout that will be called in the
Activity…and then in the
Activityyou simply create a method, calledplay(View view)