well... just figured it out :P
I've just changed the create dialog method like this (in bold the parts
changing):
public Dialog create(*final Activity activity*, String title, String
> message, int icon, final int dialogIdCode) {
> AlertDialog.Builder builder = new AlertDialog.Builder(*activity*);
> builder.setCancelable(false)
> .setTitle(title)
> .setIcon(icon)
> .setMessage(message)
> .setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() {
>
> @Override
> public void onClick(DialogInterface dialog, int which) {
> *activity*.dismissDialog(dialogIdCode);
> }
> });
>
> Dialog dialog = builder.create();
> return dialog;
> }
Anyway, is there any better way on doing this? Thanks!
2011/5/21 luiX_ <[email protected]>
> Hi,
>
> I was trying to have a class for generating a Dialog that is quite common
> in my app, the idea is to call this method from different classes
> onCreateDialog method, so I wrote this piece of code:
>
> public class DialogGenerator extends Activity {
> public static final int DIALOG = 33;
>
> public Dialog create(Context context, String title, String message, int
> icon, final int dialogIdCode) {
> AlertDialog.Builder builder = new AlertDialog.Builder(context);
> builder.setCancelable(false)
> .setTitle(title)
> .setIcon(icon)
> .setMessage(message)
> .setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() {
>
> @Override
> public void onClick(DialogInterface dialog, int which) {
> *dismissDialog(dialogIdCode); // here is where I'm having trouble*
> }
> });
>
> Dialog dialog = builder.create();
> return dialog;
> }
> }
>
>
> then, I wrote this piece for the onCreateDialog method:
>
> @Override
>> protected Dialog onCreateDialog(int id) {
>> // TODO Auto-generated method stub
>> Dialog dialog = null;
>> DialogGenerator dg = new DialogGenerator();
>> Log.e("DEBUG", "Devolvemos dialog...");
>> dialog = dg.create(this, "titulo", "mensaje", R.drawable.icon,
>> DialogGenerator.DIALOG);
>> return dialog;
>> }
>
>
> and then call the showDialog like this:
>
> showDialog(DialogGenerator.DIALOG);
>
>
> The dialog shows up right, but the problem I'm having is that I get an
> IllegalArgumentException when dismissing:
>
> 05-21 13:33:17.163: ERROR/AndroidRuntime(6114):
>> java.lang.IllegalArgumentException: no dialog with id 33 was ever shown via
>> Activity#showDialog
>
>
> Any ideas on how this can be solved? is there any tutorial on how to keep
> all the dialog in one independent class?
>
> Thank you guys!
>
--
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