• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How do you show a dialog when in a fragment?

nleigh

Lurker
1st post so not sure if im in the right section, been looking online but cant find a solution. The app is a menu for a restaurant want to navigat between mains/starters...

Im using a view pager to be able to slide to different tabs.
Each of the pages are a fragment class. Ive put a button in one of them and when I press it I just want to show a simple yes/no dialog box.

Im just using this for the dialog fragment

package com.example.pie;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;

public class PieChoiceDialogFragment extends DialogFragment {

//public static PieChoiceDialogFragment newInstance() {
// PieChoiceDialogFragment frag = new PieChoiceDialogFragment();
// return frag;
// }
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Pie Choice")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}

}


this is my fragment that im trying to show the dialog when the button is pressed

package com.example.pie;

import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class StartersFragment extends Fragment{


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.starters_fragment,
container, false);

return rootView;
}
public void onClick_buttonDialog(){
PieChoiceDialogFragment df = new PieChoiceDialogFragment();

df.show(getFragmentManager(), "dialog");
}

}

But I get the error in the df.show bit
The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentManager, String)

I dont know how to fix this, any help appreciated thanks :)
 
Back
Top Bottom