我创建了警报对话框,当我单击按钮时它没有显示。它的应用程序崩溃了。我的代码如下。我的代码有什么问题?请帮我!!
backBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
TestHopeQueue.this);
// set title
alertDialogBuilder.setTitle("Remove Download");
// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
for (int k = 0; k < trlist.size(); k++) {
if (trlist.get(k) != null) {
View v13 = linearlayout
.getChildAt(k);
TextProgressBar pr = (TextProgressBar) v13
.findViewById(R.id.progressBar);
if (pr.getProgress() < 100) {
trlist.get(k).interrupt();
trlist.set(k, null);
ViewVideoDelete(k);
Button btnDownButton = (Button) v13
.findViewById(R.id.btnDownload);
btnDownButton
.setVisibility(View.VISIBLE);
pr.setProgress(0);
pr.invalidate();
pr.setText("" + 0 + "%");
Button btnDelete = (Button) v13
.findViewById(R.id.btnDelete);
btnDelete
.setVisibility(View.GONE);
downloadqueuelist.remove(0);
if (k % 2 == 0) {
v13.setBackgroundColor(Color
.parseColor("#f8f8ff"));
// convertView.setBackgroundResource(R.drawable.whitebackground);
} else {
v13.setBackgroundColor(Color
.parseColor("#DCDCDC"));
// convertView.setBackgroundResource(R.drawable.greybackground);
}
}
} else {
TestHopeQueue.this.finish();
}
}
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
//alertDialog.show();
for (int k = 0; k < trlist.size(); k++) {
if (trlist.get(k)!= null) {
Log.v("log_tag"," Alert Dialog ");
break;
} else {
TestHopeQueue.this.finish();
}
}
AlertDialog alertDialog = new AlertDialog.Builder(TestHopeQueue.this).create();
//AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
});
我在下面得到错误::
04-13 12:38:58.112: E/WindowManager(576): Activity com.example.testhopequeue.TestHopeQueue has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40585268 that was originally added here
04-13 12:38:58.112: E/WindowManager(576): android.view.WindowLeaked: Activity com.example.testhopequeue.TestHopeQueue has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40585268 that was originally added here
04-13 12:38:58.112: E/WindowManager(576): at android.view.ViewRoot.<init>(ViewRoot.java:258)
04-13 12:38:58.112: E/WindowManager(576): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-13 12:38:58.112: E/WindowManager(576): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-13 12:38:58.112: E/WindowManager(576): at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-13 12:38:58.112: E/WindowManager(576): at android.app.Dialog.show(Dialog.java:241)
04-13 12:38:58.112: E/WindowManager(576): at com.example.testhopequeue.TestHopeQueue$1.onClick(TestHopeQueue.java:180)
04-13 12:38:58.112: E/WindowManager(576): at android.view.View.performClick(View.java:2485)
04-13 12:38:58.112: E/WindowManager(576): at android.view.View$PerformClick.run(View.java:9080)
04-13 12:38:58.112: E/WindowManager(576): at android.os.Handler.handleCallback(Handler.java:587)
04-13 12:38:58.112: E/WindowManager(576): at android.os.Handler.dispatchMessage(Handler.java:92)
04-13 12:38:58.112: E/WindowManager(576): at android.os.Looper.loop(Looper.java:130)
04-13 12:38:58.112: E/WindowManager(576): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-13 12:38:58.112: E/WindowManager(576): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 12:38:58.112: E/WindowManager(576): at java.lang.reflect.Method.invoke(Method.java:507)
04-13 12:38:58.112: E/WindowManager(576): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-13 12:38:58.112: E/WindowManager(576): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-13 12:38:58.112: E/WindowManager(576): at dalvik.system.NativeStart.main(Native Method)