May 1, 2010

[SOLVED] Error on creating custom dialog

> Use dialog = new Dialog(this);
> instead of
> dialog = new Dialog(getApplicationContext());


private void showAbout() {
showDialog(DIALOG_ABOUT_ID);
}

protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG_ABOUT_ID:
dialog = new Dialog(this);

dialog.setContentView(R.layout.about);
dialog.setTitle("Custom Dialog");
dialog.setOwnerActivity(this);

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.ic_contact_picture);

break;
// case DIALOG_GAMEOVER_ID:
// // do the work to define the game over Dialog
// break;
default:
dialog = null;
}
return dialog;
}






Source: Custom Dialog - Android Developers | Google Groups.

No comments:

Post a Comment