Code example for DialogFragment

Methods: onAttach

    private Listener mListener;
    private String mRate;
    public void onAttach(Activity activity) {
        // Verify that the host activity implements the callback interface 
        try { 
            // Instantiate the NoticeDialogListener so we can send events to the host 
            mListener = (Listener) activity;
        } catch (ClassCastException e) {
            // The activity doesn't implement the interface, throw exception 
            throw new ClassCastException(activity.toString()
                    + " must implement SampleRateDialog.Listener"); 
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // read the current preference 
        SharedPreferences prefs = getActivity().getSharedPreferences(SensePrefs.MAIN_PREFS,