I am using example for creating custom dialogs on dev.android.com.
See code below.

The problem is that second line is crashing application (fore close)
######  Context mContext = getApplicationContext();
I can make dialog to work if I replace line with
######  Context mContext = this;

My questions:
1) I have read somewhere that I shouldn't be using "this", that I
should be using getApplicationContext because context can be lost when
changing orientation or so... Should I?  Not really even sure if I
understand what the context is...
2) in another example there is line MyActivity.this.finish();  (it is
located in onclick listener for YES button in AlertDialog)  Android
doesn't know what is MyActivity. What am I doing wrong?

Thanks,

Sorry, absolute beginner.


protected Dialog onCreateDialog(int id) {
    Context mContext = getApplicationContext();
    Dialog dialog = new Dialog(mContext);

    dialog.setContentView(R.layout.custom_dialog);
    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.android);
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to