Java 当我再次运行AlertDialog时,它会关闭
我这样使用我的AlertDialog,当我第二次运行它时,它关闭了。我真的是新来的,我不知道这是否是因为AlertDialog的使用在这里是错误的` 真的很期待答案。非常感谢Java 当我再次运行AlertDialog时,它会关闭,java,android,Java,Android,我这样使用我的AlertDialog,当我第二次运行它时,它关闭了。我真的是新来的,我不知道这是否是因为AlertDialog的使用在这里是错误的` 真的很期待答案。非常感谢 AlertDialog aler = null; @Override public void onClick(View v) { switch (v.getId()) { case R.id.start: aler=null; final EditText filename
AlertDialog aler = null;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.start:
aler=null;
final EditText filename = new EditText(this);
Builder alerBuidler = new Builder(this);
alerBuidler
.setTitle("enter the name")
.setView(filename)
.setPositiveButton("require",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
String text = filename.getText().toString();
try {
paths = path
+ "/"
+ text
+ new SimpleDateFormat(
"yyyyMMddHHmmss").format(System
.currentTimeMillis())
+ ".amr";
saveFilePath = new File(paths);
myRecorder.setOutputFile(saveFilePath
.getAbsolutePath());
saveFilePath.createNewFile();
myRecorder.prepare();
// start recording
myRecorder.start();
start.setText("recording。。");
start.setEnabled(false);
aler.dismiss();
// read files again
File files = new File(path);
listFile = files.list();
// fresh ListView
showRecord.notifyDataSetChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
});
aler = alerBuidler.create();
aler.setCanceledOnTouchOutside(false);
aler.show();
break;`
我的猜测是,您正在对话框中完成所有录制工作,但它没有关闭。
正确的方法是在你的活动或片段中添加一个NotifiedAloglistener,然后在那里完成工作。我也猜问题在于对话框没有关闭,但不知道如何解决这种情况。我将尝试你建议的方法,谢谢!