我在线程中使用 ProgressDialog
。在 onButtonClick
中,线程已启动,但当我触摸屏幕上的任何位置时,ProgressDialog
将关闭。
如何防止这种情况发生?
private void ButtonClick(View view) {
btn1 = (Button) view.findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
GetStudentData();
}
});
}
private synchronized void GetStudentData() {
try {
// Thread to display loader
new Thread() {
@Override
public void run() {
Looper.prepare();
dialog = Msg.ShowProgressDialogBox(
getActivity(),
dialog,
"Please wait while we fetch the student data...");
Looper.loop();
}
}.start();
new Thread() {
@Override
public void run() {
String studentData="Kailas";
}
}
} catch(Exception ex {
}
}
更新
当我触摸屏幕时,ProgressDialog
会消失,但会获取所有数据。
最佳答案
将此添加到您的对话框中:
yourDialog.setCanceledOnTouchOutside(false);
这样你就可以触屏了,Dialog不会被取消。
编辑
如果你使用的是DialogFragment
,那么你必须在调用show(FragmentManager mng, String tag)之前使用下面的代码 fragment :
更多信息 here .
dialogFragment.setCancelable(false);
编辑 2
小心 ProgressDialog
,因为 Android Oreo (v8.0) 现在已弃用它。
关于android - 触摸屏幕时关闭进度对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19655715/