我有一个对话框和一个线程。线程完成后,我想执行对话框。问题有时是执行,有时不是。我不明白为什么会这样。
我该如何解决?
/** display dialog */
private void showDialog(int status){
final Dialog dialog = new Dialog(getView().getContext());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
dialog.setContentView(R.layout.custom_dialog);
dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
dialog.setCancelable(false);
ImageView ivCustomDialog = (ImageView) dialog.findViewById(R.id.ivCustomDialog);
Button dialogButton = (Button) dialog.findViewById(R.id.btnProsseguir);
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
线
new Thread(){
public void run(){
int count = 0;
while(count < 100){
if(count >= 100){
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
showDialog(1);
interrupt();
}
});
}
count++;
}
}
}.start();