Reputation: 23596
In My application i need to open one dialog. And on press of button on that dialog i want to open another dialog and do some action. Both the dialog are custom dialog. But while i do that i am not able to create the dialog...
See below code:
twsbiImageDialog = new Dialog(this,R.style.CustomDialogTheme);
twsbiImageDialog.setContentView(R.layout.twsbi_logo_dialog);
twsbiImageDialog.setCancelable(true);
// To visit Website ===================================
Button visitWebsiteButton = (Button) twsbiImageDialog.findViewById(R.id.visitWebsiteButton);
visitWebsiteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
twsbiImageDialog.dismiss();
Intent in = new Intent(FingerPaint.this,GoogleSite.class);
startActivity(in);
}
});
// For About ===================================
Button aboutButton = (Button) twsbiImageDialog.findViewById(R.id.aboutButton);
aboutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
twsbiImageDialog.dismiss();
//System.out.println("I Am here before Dialog");
aboutDialog = new Dialog(getApplicationContext(),R.style.CustomDialogTheme);
aboutDialog.setContentView(R.layout.about_dialog);
aboutDialog.setCancelable(true);
Button okButton = (Button) aboutDialog.findViewById(R.id.okButton);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
aboutDialog.dismiss();
}
});
aboutDialog.show();
//openAboutDialog();
}
});
twsbiImageDialog.show();
And If i do like that i got the error like below:
12-05 11:43:21.568: ERROR/AndroidRuntime(545): FATAL EXCEPTION: main
12-05 11:43:21.568: ERROR/AndroidRuntime(545): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.view.ViewRoot.setView(ViewRoot.java:509)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.app.Dialog.show(Dialog.java:241)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at com.project.twsbi.FingerPaint$8.onClick(FingerPaint.java:546)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.view.View.performClick(View.java:2408)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.view.View$PerformClick.run(View.java:8816)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.os.Handler.handleCallback(Handler.java:587)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.os.Handler.dispatchMessage(Handler.java:92)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.os.Looper.loop(Looper.java:123)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at java.lang.reflect.Method.invoke(Method.java:521)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-05 11:43:21.568: ERROR/AndroidRuntime(545): at dalvik.system.NativeStart.main(Native Method)
Upvotes: 0
Views: 136
Reputation: 4580
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout......);
context = this;
}
Dialog inside dialog:
aboutDialog = new Dialog(context, R.style.CustomDialogTheme);
aboutDialog.setContentView(R.layout.about_dialog);
aboutDialog.setCancelable(true);
Upvotes: 2
Reputation: 5183
Use the current activity as context:
aboutDialog = new Dialog(ActivityName.this,R.style.CustomDialogTheme);
Upvotes: 2
Reputation: 3204
I think dont use getApplicationContext() in your button second dialog open code. Use the context of this page.
Try this, It may be help you.
Upvotes: 2