Reputation: 401
When I create a dialog upon a Button click, I get an error. How can I show a dialog upon a Button click?
My main class extends Activity.
deleteentry.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new deleteOptionsDialog(getApplicationContext()).show();
}
});
public class deleteOptionsDialog extends Dialog {
public deleteOptionsDialog(final Context context) {
super(context, android.R.style.Theme_Translucent);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.delete_options_dialog);
RelativeLayout cameraLayout = (RelativeLayout) findViewById(R.id.rldelete);
cameraLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
Upvotes: 0
Views: 69
Reputation: 1662
For Dialog
instance you should use Activity context, not getApplicationContext()
and not getApplication()
, but YourActivity.this
And it's a better idea to instanciate dialog somewhere in onCreate() an later check if it is showing when trying to show once more
Upvotes: 0
Reputation: 2157
try use new deleteOptionsDialog(YourCurrentActivity.this).show();
Problem in use getApplicationContext()
in creating dialog
Upvotes: 0
Reputation: 11131
replace
new deleteOptionsDialog(getApplicationContext()).show();
with
new deleteOptionsDialog(YourActivity.this).show();
and try to move all your code inside Constructor
to onCreate()
method of Dialog
by overriding it.
Upvotes: 0