Skip to content Skip to sidebar Skip to footer

Dialog Crashing The App

Ok just to know,I copy-pasted the code from the android website,so I don't think there is something wrong. The problem is that when I press the button it crashes.And it crashes fro

Solution 1:

You use the Activity context and add a call to dialog.show();:

    Context mContext = this; //Assumes you are calling this from within an activity
    Dialog dialog = new Dialog(mContext);

    dialog.setContentView(R.layout.maindialog);
    dialog.setTitle("Custom Dialog");

    TextView text = (TextView) dialog.findViewById(R.id.text);
    text.setText("Hello, this is a custom dialog!");
    ImageView image = (ImageView) dialog.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon);    
    dialog.show();  

Post a Comment for "Dialog Crashing The App"