0
我有一個對話框和一個線程。線程完成後,我想執行對話框。問題有時會執行,有時不會。我不明白爲什麼會發生這種情況。線程不執行對話框?
我該如何解決?
/** 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();
你確定你的代碼中有這個:'int count <0;'? – 2014-12-05 12:59:49
哇,對不起,我編輯過! :) – FernandoPaiva 2014-12-05 13:00:55
你想在'while(count <100)'中添加一些延遲嗎?爲什麼不使用'Thread.sleep'? – 2014-12-05 13:02:16