如果用户正在录制声音,我为对话框创建了一个java类。单击“停止”按钮时我有何React?我想停止我主要活动的录音。
下面是我的对话代码:
public class RecordDialog extends AppCompatDialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Recording...")
.setIcon(R.drawable.ic_record)
.setPositiveButton ("Stop", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
}
主要活动:
public void openRecordDialog(View view) {
if (view.getId() == R.id.btnRec1) {
record();
RecordDialog recordDialog = new RecordDialog();
recordDialog.show(getSupportFragmentManager(), "Recording...");
}
}
private void record() {
try {
mediaRecorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
}
private void stop(){
mediaRecorder.stop();
mediaRecorder.release();
}
单击mainactivity中的按钮,onclick将启动openrecorddialog()方法。
如何通过单击对话框中的positivebutton来启动stop方法?
谢谢
1条答案
按热度按时间8cdiaqws1#
我想知道,处理这个问题的最佳方法是从
onCreateDialog
方法:然后你像这样使用它: