Reputation: 991
I've created a dialog and am having trouble showing it inside my main activity's on create method.
I'm calling show
on the object like this:
FireMissilesDialogFragment newFragment = new FireMissilesDialogFragment();
newFragment.show();
But I get an error saying that it can't resolve method 'show'
This is my Dialog code (I'm learning how to make them so this is a copy from android dev site dialog training)
package com.shush;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
public class FireMissilesDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.name)
.setPositiveButton(R.string.name, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton(R.string.address, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
Upvotes: 1
Views: 871
Reputation: 59274
Instead of
FireMissilesDialogFragment newFragment = new FireMissilesDialogFragment();
newFragment.show();
use:
DialogFragment newFragment = new FireMissilesDialogFragment();
newFragment.show(getSupportFragmentManager(), "firemissile");
Upvotes: 1