을 구현하는 방법) 사운드를 삭제합니다. 이 접근법의 어려움은 언제 값을 재설정할지 정의하는 것입니다.
private int _clicks = 0;
k = (Button)findViewById(R.id.button1);
k.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int count = ++_clicks;
if(count == 1)
//do whatever
if(count == 2)
//do whatever
if(count == 3)
//do whatever
}
});
더 나은 방법은 여러 개의 단추에 여러 개의 처리기를 지정하고 단추에 필요한 작업을 수행하는 것입니다. 이렇게하면 1 : 1 관계를 정의 할 수 있으며 코드를 훨씬 더 쉽게 관리 할 수 있습니다.
편집 : 소리를 녹음하려면 웹상에 plenty of examples이 있습니다.
public class AudioRecorder {
final MediaRecorder recorder = new MediaRecorder();
final String path;
/**
* Creates a new audio recording at the given path (relative to root of SD card).
*/
public AudioRecorder(String path) {
this.path = sanitizePath(path);
}
private String sanitizePath(String path) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.contains(".")) {
path += ".3gp";
}
return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}
/**
* Starts a new recording.
*/
public void start() throws IOException {
String state = android.os.Environment.getExternalStorageState();
if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("SD Card is not mounted. It is " + state + ".");
}
// make sure the directory we plan to store the recording in exists
File directory = new File(path).getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
}
/**
* Stops a recording that has been previously started.
*/
public void stop() throws IOException {
recorder.stop();
recorder.release();
}
}
U 내가 어떻게 말할 수 첫 번째 클릭으로 사운드 녹음 – Ramz
@ user1103284 편집 추가, 녹음 소리에 대한 참조 –
재생할 때 감사합니다 – Ramz